maven-compiler-plugin 3.6.0 不编译从注释生成的源代码 [英] maven-compiler-plugin 3.6.0 doesn't compile generated sources from annotations

查看:53
本文介绍了maven-compiler-plugin 3.6.0 不编译从注释生成的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

此模块的一些注释生成的源被另一个模块使用,并且找不到类文件.发生了什么变化?generate-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>元素管理器的JPA实体</description><artifactId>em-model</artifactId><groupId>com.myprod.em</groupId><父母><artifactId>em</artifactId><groupId>com.myprod</groupId><version>3.5.0.0.0-SNAPSHOT</version></父母><包装>罐</包装><构建><插件><插件><groupId>org.codehaus.mojo</groupId><artifactId>build-helper-maven-plugin</artifactId><执行><执行><phase>process-sources</phase><配置><来源><source>${project.build.directory}/generated-sources/annotations</source></来源></配置><目标><goal>add-source</goal></目标></执行></执行></插件><插件><artifactId>maven-jar-plugin</artifactId><groupId>org.apache.maven.plugins</groupId><配置><finalName>em-model</finalName></配置></插件><插件><artifactId>maven-compiler-plugin</artifactId><配置><compilerArgument>-proc:none</compilerArgument></配置><执行><执行><id>run-annotation-processors-only</id><phase>generate-sources</phase><配置><compilerArgument>-proc:only</compilerArgument></配置><目标><目标>编译</目标></目标></执行></执行></插件></plugins></build><依赖项><依赖><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId></依赖><依赖><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><范围>提供</范围></依赖><依赖><groupId>org.glassfish</groupId><artifactId>javax.el</artifactId><version>3.0.1-b08</version><范围>测试</范围></依赖><依赖><groupId>org.jboss.spec.javax.ejb</groupId><artifactId>jboss-ejb-api_3.2_spec</artifactId><范围>提供</范围></依赖><!-- 由于在单元测试中使用了休眠验证器,需要这些 JBoss 日志记录 --><依赖><groupId>org.jboss.slf4j</groupId><artifactId>slf4j-jboss-logmanager</artifactId><范围>提供</范围></依赖><依赖><groupId>org.jboss.logmanager</groupId><artifactId>jboss-logmanager</artifactId><范围>提供</范围></依赖><依赖><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><范围>提供</范围></依赖><依赖><groupId>org.codehaus.jackson</groupId><artifactId>jackson-mapper-asl</artifactId><version>1.8.5</version><范围>提供</范围></依赖><依赖><groupId>org.apache.commons</groupId><artifactId>commons-io</artifactId><version>1.3.2</version><范围>提供</范围></依赖><依赖><groupId>com.myco.csp</groupId><artifactId>nrp_jpa</artifactId><范围>提供</范围></依赖><依赖><groupId>com.myco.cim</groupId><artifactId>cs_cim_jpa</artifactId><范围>提供</范围></依赖><依赖><groupId>org.hibernate</groupId><artifactId>hibernate-jpamodelgen</artifactId><version>1.0.0.Final</version><范围>提供</范围></依赖><!-- 测试--><依赖><groupId>junit</groupId><artifactId>junit</artifactId><范围>测试</范围></依赖><依赖><groupId>org.mockito</groupId><artifactId>mockito-all</artifactId></依赖><依赖><groupId>com.myco.logging</groupId><artifactId>logging-client</artifactId><范围>提供</范围></依赖><依赖><groupId>apache-log4j</groupId><artifactId>log4j</artifactId><范围>提供</范围></依赖><依赖><groupId>com.myprod.prodCommon</groupId><artifactId>unit-test-utils</artifactId><version>${project.version}</version><范围>测试</范围></依赖></依赖项>

解决方案

我通过从编译器插件中删除 -proc:none 编译器参数解决了这个问题.有了这个,生成的源代码根本没有被编译.使用 3.1 插件我必须拥有它,但使用 3.6.0 我不能.

我还尝试通过使compilerArg 特定于默认编译阶段,但不会编译生成的源代码.如果我不重用默认编译 id,构建会工作并为我生成类文件,但它运行了两个编译阶段,-proc:none 一秒钟,这似乎是多余的.>

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

<artifactId>maven-compiler-plugin</artifactId><执行><执行><id>run-annotation-processors-only</id><phase>generate-sources</phase><配置><compilerArgument>-proc:only</compilerArgument></配置><目标><目标>编译</目标></目标></执行></执行></插件>

We just upgraded our JBoss from 6.1.0 to Wildfly 10.1, and made a variety of associated upgrades to modules and artifact versions and so on. In one module this caused our cobertura compiles to fail with a compiler error. I found IllegalStateException in Hibernate metamodel generation with maven and upgraded to maven-compiler-plugin 3.6.0 (from 3.1). This seemed to resolve my problem, but only on a local basis. I can compile the module for cobertura, but it turns out to cause a new problem.

Some of the annotation-generated sources for this module are used by another module, and the class files aren't found. What changed? The generated-sources directory contains the java files, but the classes aren't compiled.

It looked at one point like changing the build-helper phase to generate-sources from process-sources helped, but that failed subsequently.

Is there something else that needs to be changed because of changes between 3.1 and 3.6.0? (I'm not familiar with how to process annotations - I'm just the Cobertura support guy.)

pom file:

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

解决方案

I resolved this by removing the -proc:none compiler argument from the compiler plugin. With that present none of the generated sources were being compiled at all. With the 3.1 plugin I had to have that, but with 3.6.0 I can't.

I also tried to implement the answer https://stackoverflow.com/a/35045416/4756238 by making the compilerArg specific to the default-compile phase, but that didn't compile the generated sources. If I didn't reuse the default-compile id the build worked and gave me generated class files, but it ran two compile phases, with the -proc:none one second, which seemed redundant.

The final pom section for the compiler looks like this:

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

这篇关于maven-compiler-plugin 3.6.0 不编译从注释生成的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆