【问题标题】:Java classes generated using maven exec-maven-plugin “target” folder are not compiled使用 maven exec-maven-plugin “target” 文件夹生成的 Java 类未编译
【发布时间】:2020-04-07 08:21:39
【问题描述】:

我有一个 maven 项目,它使用 exec-maven-plugin 将 java 类生成到目标/生成源中。 在 mvn clean install 期间永远不会编译下面生成的 java 类。

           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                       <sources>
                 <source>${project.build.directory}/foldername</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <id>add-sources</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <phase>prepare-package</phase>
                    <configuration>
                        <mainClass>mainclass</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我必须为此使用 MOJO 吗?

【问题讨论】:

  • @Daniele maven-source-plugin 与此无关。您应该使用mojohaus.org/build-helper-maven-plugin 并将源代码添加到编译区域...
  • @khmarbaise 感谢您指出 out-user2916626 您可以分享 maven 项目吗?您应该为 build-helper-maven-plugin 添加一些配置,以将生成的源文件夹添加到正在编译的集合中

标签: java maven maven-plugin


【解决方案1】:

使用build-helper-maven-plugin可以配置如下:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>some directory</source>
                ...
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

【讨论】:

  • 我正在使用 codehaus.mojo 插件在“准备包”阶段将我的 java 类执行到目标目录中的生成源中。后来我想为java类生成.class文件
猜你喜欢
  • 2016-01-17
  • 1970-01-01
  • 1970-01-01
  • 2019-04-18
  • 1970-01-01
  • 2011-10-05
  • 1970-01-01
  • 2016-02-19
  • 1970-01-01
相关资源
最近更新 更多