java - maven-compiler-plugin 3.6.0 不编译从注释生成的源

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

我们刚刚将 JBoss 从 6.1.0 升级到 Wildfly 10.1,并对模块和 Artifact 版本等进行了各种相关升级。在一个模块中,这导致我们的 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>

最佳答案

我通过删除 -proc:none 解决了这个问题来自编译器插件的编译器参数。目前,根本没有编译任何生成的源代码。对于 3.1 插件,我必须拥有它,但对于 3.6.0,我不能。

我也尝试实现答案 https://stackoverflow.com/a/35045416/4756238通过制作 compilerArg特定于默认编译阶段,但没有编译生成的源代码。如果我没有重用默认编译 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>

关于java - maven-compiler-plugin 3.6.0 不编译从注释生成的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49160582/

相关文章:

java - Maven 没有从依赖模块中获取类

java - 找不到类型 : java. lang.Long :No validator could be found for type: java. lang.Long 的 validator

java - 与基于 xml 的配置相比,注释在重新编译、重新部署方面不是有显着的优势吗?

spring - 如果有@Entity,为什么需要 "annotatedClasses"?

java - "java.sql.SQLException: Access denied for user ' 根 '@' 本地主机 ' (using password: YES)"

java - ISO-8858-1 到 UTF-8 仅在 URL 中,仅无效字符

java - Maven 和 Jenkins 有什么区别?

java - Hibernate映射不成功-不知道错误发生在哪里

java - 离线/在线数据同步策略

java - Scala-Java 互操作,方法重载问题(数组和可变参数)