maven-compiler-plugin 3.6.0不会从注释

时间:2018-03-07 20:23:03

标签: java maven annotations hibernate-annotations maven-compiler-plugin

我们刚刚将JBoss从6.1.0升级到Wildfly 10.1,并对模块和工件版本进行了各种相关的升级,等等。在一个模块中,这导致我们的cobertura编译失败并出现编译器错误。我找到IllegalStateException in Hibernate metamodel generation with maven并升级到maven-compiler-plugin 3.6.0(从3.1开始)。这似乎解决了我的问题,但仅限于本地。我可以为cobertura编译模块,但结果却引发了一个新问题。

该模块的一些注释生成的源由另一个模块使用,并且找不到类文件。改变了什么? generated-sources目录包含java文件,但是这些类没有编译。

它考虑了一点,例如将构建辅助阶段更改为来自流程源的生成源有帮助,但随后失败了。

由于3.1和3.6.0之间的变化,是否还需要更改其他内容? (我不熟悉如何处理注释 - 我只是Cobertura的支持人员。)

pom文件:

<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>

<description>The JPA entities for the Element Manager</description>

<artifactId>em-model</artifactId>
<groupId>com.myprod.em</groupId>

<parent>
    <artifactId>em</artifactId>
    <groupId>com.myprod</groupId>
    <version>3.5.0.0.0-SNAPSHOT</version>
</parent>

<packaging>jar</packaging>

<build>
    <plugins>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>      
               <execution> 
                  <phase>process-sources</phase>
                  <configuration>
                     <sources>
                         <source>${project.build.directory}/generated-sources/annotations</source>
                     </sources>
                  </configuration>
                  <goals>
                     <goal>add-source</goal>
                  </goals>
               </execution>
            </executions>
        </plugin>        

        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <groupId>org.apache.maven.plugins</groupId>
            <configuration>
                <finalName>em-model</finalName>
            </configuration>
        </plugin>

        <plugin>
               <artifactId>maven-compiler-plugin</artifactId>
               <configuration>
                  <compilerArgument>-proc:none</compilerArgument>
               </configuration>
               <executions>
                  <execution>
                     <id>run-annotation-processors-only</id>
                     <phase>generate-sources</phase>
                     <configuration>
                        <compilerArgument>-proc:only</compilerArgument>                            
                     </configuration>
                     <goals>
                        <goal>compile</goal>
                     </goals>
                  </execution>
               </executions>  
        </plugin>

    </plugins>        
</build>

<dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.el</artifactId>
        <version>3.0.1-b08</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Since hibernate validator is used in unit tests, 
         these JBoss logging deps are needed -->        
    <dependency>
        <groupId>org.jboss.slf4j</groupId>
        <artifactId>slf4j-jboss-logmanager</artifactId>
        <scope>provided</scope>    
    </dependency>
     <dependency>
        <groupId>org.jboss.logmanager</groupId>
        <artifactId>jboss-logmanager</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
        <scope>provided</scope>
    </dependency>    
    <dependency>
        <groupId>com.myco.csp</groupId>
        <artifactId>nrp_jpa</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.myco.cim</groupId>
        <artifactId>cs_cim_jpa</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-jpamodelgen</artifactId>
           <version>1.0.0.Final</version>
           <scope>provided</scope>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
    </dependency>
    <dependency>
        <groupId>com.myco.logging</groupId>
        <artifactId>logging-client</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>apache-log4j</groupId>
        <artifactId>log4j</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.myprod.prodCommon</groupId>
        <artifactId>unit-test-utils</artifactId>
        <version>${project.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:1)

我通过从编译器插件中删除-proc:none编译器参数来解决这个问题。目前,没有任何生成的源被编译。使用3.1插件我必须拥有它,但是使用3.6.0我不能。

我还尝试通过使compilerArg特定于默认编译阶段来实现答案https://stackoverflow.com/a/35045416/4756238,但是没有编译生成的源。如果我没有重用default-compile id,那么构建工作并给了我生成的类文件,但它运行了两个编译阶段,-proc:none一秒,这似乎是多余的。

编译器的最终pom部分如下所示:

<plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <executions>
     <execution>
       <id>run-annotation-processors-only</id>
       <phase>generate-sources</phase>
       <configuration>
         <compilerArgument>-proc:only</compilerArgument>
       </configuration>
       <goals>
         <goal>compile</goal>
       </goals>
     </execution>
   </executions>
</plugin>
相关问题