简体   繁体   English

Maven编译器插件,构建帮助器插件不会生成类文件

[英]Maven compiler plugin, build helper plugin does not generate class files

I am trying to convert an existing project into a maven project. 我正在尝试将现有项目转换为Maven项目。 It has 3 modules and one of the modules has multiple source folders. 它具有3个模块,其中一个模块具有多个源文件夹。 http://i.imgur.com/jZCnR.png http://i.imgur.com/jZCnR.png

A maven clean and install or an eclipse clean does not create the class files in the classes and test-classes folder. Maven清理并安装或Eclipse清理不会在classes和test-classes文件夹中创建类文件。 The project structure gets created by there are no class files there. 项目结构是通过没有类文件创建的。

The following plugin configuration is defined in the parent pom. 在父pom中定义了以下插件配置。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals><goal>add-source</goal></goals>
            <configuration>
                <sources>
                    <source>src/main/java/**/*.*</source>
                    <source>src/report/java/**/*.*</source>
                    <source>src/architect/java/**/*.*</source>
                </sources>
            </configuration>
        </execution>
        <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals><goal>add-test-source</goal></goals>
            <configuration>
                <sources>
                    <source>src/test/java/**/*.*</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <debug>false</debug>
    </configuration>
    <executions>
        <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals><goal>compile</goal></goals>
            <configuration>
                <includes>
                    <include>src/main/java/**/*.*</include>
                    <include>src/report/java/**/*.*</include>
                    <include>src/architect/java/**/*.*</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals><goal>testCompile</goal></goals>
            <configuration>
                <testIncludes>
                    <include>src/test/java/**/*.*</include>
                </testIncludes>
            </configuration>
        </execution>
    </executions>
</plugin>

What am I doing wrong? 我究竟做错了什么?

For me the mvn plugin in eclipse doesn't generate the proper structure either. 对我来说,eclipse中的mvn插件也无法生成适当的结构。 Try running mvn eclipse:eclipse in cmd. 尝试在cmd中运行mvn eclipse:eclipse。 That did it for me. 对我来说就做到了。

Also you used the phase 'generate-test-sources'. 您还使用了“ generate-test-sources”阶段。 This doesn't seem to work try 'generate-sources'. 尝试使用“生成源”似乎不起作用。

According to Using MOJO build-helper-maven-plugin to add more source folders to MAVEN you should not define additional source directories again via the includes tag; 根据使用MOJO集结帮手- Maven的插件来添加更多的源文件夹的Maven ,你应该定义额外的源目录通过再次包括标签; define them just in build-helper-maven-plugin and that is it. 仅在build-helper-maven-plugin中定义它们,就是这样。

Also you can try to associate add-source goal with an earlier Maven phase, like initialize . 另外,您可以尝试将add-source目标与早期的Maven阶段相关联,例如initialize Generally, the earlier the better. 通常,越早越好。

<phase>initialize</phase>
<goals>
    <goal>add-source</goal>
</goals>

In my case, my mistake it was to bind it to compile phase. 就我而言,我的错误是将其绑定到编译阶段。 Despite my build-helper-maven-plugin was defined before maven-compile-plugin in the pom.xml , somehow default-compile task kicked in first and silently ignored my extra source directories causing some unexpected errors further down the build. 尽管我的build-helper-maven-pluginpom.xml中的maven-compile-plugin之前定义了,但默认情况下默认编译任务首先启动,并且默默地忽略了我的额外源目录,从而在构建过程中进一步导致了一些意外错误。 Order of steps bonded to same phase should follow order of appearance in pom.xml but, well, not always. 绑定到同一阶段的步骤顺序应遵循pom.xml中出现的顺序,但是,并非总是如此。

Check that you see in your log: 检查您是否在日志中看到:

[INFO] --- build-helper-maven-plugin:1.8:add-source (add-gen-source) @ deepclone-sample-project-1 ---
[INFO] Source directory: E:\dev\workspace...\src\main\generated added.

Handy trick: Make a deliberate error in your code, just to check that compiler really go through you extra directories. 方便的窍门:在代码中故意犯一个错误,只是为了检查编译器是否确实通过了额外的目录。 If compilation does not fail instantly then the issues in not about not generating class files files but really about compiler configuration. 如果编译不会立即失败,那么问题就不在于不生成类文件,而在于真正的编译器配置。 You can exclude incremental build issues or similar more esoteric issues. 您可以排除增量构建问题或类似的更深奥的问题。

作为记录建立帮助Maven插件add-source目标,应指定目录中的<source>标签。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM