【问题标题】:How to stop findbugs-maven-plugin from validating querydsl generated class如何阻止 findbugs-maven-plugin 验证 querydsl 生成的类
【发布时间】:2013-10-31 12:54:59
【问题描述】:

如何配置 findbugs-maven-plugin 以跳过验证为 Querydsl 生成的代码? 要么 如何配置 Querydsl 以生成 QTransactions.java 到另一个包?

运行 mvn clean install 时出现以下问题:

[INFO] --- findbugs-maven-plugin:2.5.2:check (default) @ transactions ---
[INFO] BugInstance size is 1
[INFO] Error size is 0
[INFO] Total bugs: 1
[INFO] com.example.transactions.QTransaction doesn't override com.mysema.query.types.path.BeanPath.equals(Object) ["com.example.transactions.QTransaction"] At QTransaction.java:[lines 19-53]
[INFO] ------------------------------------------------------------------------

Transactions.java:

package com.example.transactions;

//imports 

@Entity(name="Transaction")
@EntityListeners({TransactionStateListener.class})
public class Transaction {

    @Id
    @GeneratedValue
    @Column(nullable = false)
    protected Long txId;

    @Column(name="txType", nullable=false)
    @Enumerated(EnumType.STRING)
    protected TransactionType type;

    @Column(name="state", nullable=false)
    @Enumerated(EnumType.STRING)
    protected TransactionState state;       

    @Transient
    protected TransactionState oldState;

    @Column(nullable=false, updatable=false)
    protected Long accountId;

    @Column(length=32)  
    protected String productId;

    @Column(length=32)
    protected String externalProductId;

    @Column(length=64)
    protected String externalTxId;

    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    @Column(updatable=false)
    protected DateTime createdDateTime;

    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    @Column(insertable=false)
    protected DateTime lastModifiedDateTime;

    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    @Column(insertable=false)
    protected DateTime executedDateTime;    

    @Version
    protected Integer version;

    @PostPersist
    @PostUpdate
    @PostLoad
    void updateOldState() {
        oldState = state;
    }

    @PrePersist
    void prePersist() throws InvalidTxStateException {
        state = TransactionState.INITIALIZED;
        createdDateTime = DateTime.now();       
    }

    @PreUpdate
    void preUpdate() {      
        lastModifiedDateTime = DateTime.now();
        if (state == TransactionState.EXECUTED) {
            executedDateTime = DateTime.now(); 
        }
    }

    //Getters and setters
}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

    ...
    <dependencies>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
        </dependency>
    </dependencies>
    ...

    <build>
         <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <configuration>
                    <onlyAnalyze>com.example.-</onlyAnalyze>
                </configuration>
            </plugin>            
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>maven-apt-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
<!--                            Specifies the directory in which the query types are generated -->
                            <outputDirectory>target/generated-sources-jpa</outputDirectory>
<!--                            States that the APT code generator should look for JPA annotations -->
                            <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>  
</project>

【问题讨论】:

    标签: java maven spring-mvc findbugs querydsl


    【解决方案1】:

    对于第一个问题,我没有答案。

    您可以通过querydsl.packageSuffix APT 选项生成要分包的 Q 类,如此处记录的http://www.querydsl.com/static/querydsl/3.2.3/reference/html/ch03s03.html#d0e1847

    【讨论】:

    • 谢谢,这帮助我找到了问题的答案。
    【解决方案2】:

    所以我环顾四周找到了解决方案,非常感谢 Timos 部分解决方案。

    基本上是两部分。

    1. 将 QueryDSL 类生成到另一个包中
    2. 从 findbugs-maven-plugin 中排除该软件包(请参阅 http://blog.sinarf.org/2009/03/exclude-generated-classes-from-findbugs.html

    pom.xml:

        ...
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <configuration>
                <failOnError>true</failOnError>
                <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
            </configuration>
        </plugin>
        ...
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>maven-apt-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                       <outputDirectory>target/generated-sources-jpa</outputDirectory>
                       <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                       <options>
                           <querydsl.packageSuffix>.generated</querydsl.packageSuffix>
                       </options>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        ...
    

    findbugs-exclude.xml:

    <FindBugsFilter>
      <Match>
        <Package name="com.example.transactions.generated" />
      </Match>
    </FindBugsFilter>
    

    【讨论】:

    • 我应该把 findbugs-exclude.xml 文件放在哪里?我尝试将它放在与父 pom 相同的文件夹中。但这没有用。有什么想法吗?
    • @Chanakaudaya 我将 indbugs-exclude.xml 文件放在与父 pom 相同的文件夹中,它可以工作。所以,一定是你的配置有问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 2015-06-18
    相关资源
    最近更新 更多