简体   繁体   English

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

[英]maven-compiler-plugin 3.6.0 doesn't compile generated sources from annotations

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. 我们刚刚将JBoss从6.1.0升级到Wildfly 10.1,并对模块和工件版本等进行了各种关联的升级。 In one module this caused our cobertura compiles to fail with a compiler error. 在一个模块中,这导致我们的cobertura编译失败并出现编译器错误。 I found IllegalStateException in Hibernate metamodel generation with maven and upgraded to maven-compiler-plugin 3.6.0 (from 3.1). 在使用Maven的Hibernate元模型生成中发现了IllegalStateException,并升级到了maven-compiler-plugin 3.6.0(从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. 我可以为cobertura编译模块,但事实证明这会引起新的问题。

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. Generated-sources目录包含Java文件,但未编译这些类。

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? 由于3.1和3.6.0之间的变化,是否还需要更改其他内容? (I'm not familiar with how to process annotations - I'm just the Cobertura support guy.) (我不熟悉如何处理注释-我只是Cobertura支持人员。)

pom file: 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>

I resolved this by removing the -proc:none compiler argument from the compiler plugin. 我通过从编译器插件中删除-proc:none编译器参数来解决此问题。 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. 使用3.1插件时,我必须拥有它,但使用3.6.0时,我则不需要。

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. 我还尝试通过使compilerArg特定于默认编译阶段来实现答案https://stackoverflow.com/a/35045416/4756238 ,但这并未编译生成的源。 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. 如果我不重用默认编译ID,则该构建工作并为我提供了生成的类文件,但是它运行了两个编译阶段,其中-proc:none一秒钟,这似乎很多余。

The final pom section for the compiler looks like this: 编译器的最后一个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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 maven-compiler-plugin:3.1:编译失败。 空指针异常 - maven-compiler-plugin:3.1:compile failed. NullPointerException 编译错误:无法执行 maven-compiler-plugin:2.3.2:compile - COMPILATION ERROR : Failed to execute maven-compiler-plugin:2.3.2:compile maven-compiler-plugin 3.2编译错误:找不到符号 - maven-compiler-plugin 3.2 compile error: cannot find symbol maven-compiler-plugin:3.8.1:compile throwing NullPointerException - maven-compiler-plugin:3.8.1:compile throwing NullPointerException 找不到 maven 编译器插件 - maven-compiler-plugin not found 使用 maven-compiler-plugin 排除包适用于一个包但不适用于另一个包 - Excluding package with maven-compiler-plugin works for one package but doesn't work for another 在 maven org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile 目标期间出现错误 - Getting error duing maven org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile goal 使用 maven-compiler-plugin 从编译中排除 src/main/java - exclude src/main/java from compiling with maven-compiler-plugin Maven:未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.10.1compile: - Maven: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile Maven忽略了“ maven-compiler-plugin”要求 - Maven ignores the “maven-compiler-plugin” requirements
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM