+-
java – 在maven项目中从编译中有条件地排除文件
在maven项目中有条件地从编译中排除 java文件的最简单/最正确的方法是什么?

我希望能够在pom.xml中设置’boolean’属性:

<properties>
    <IncludeMayBe>true</IncludeMayBe>
</properties>

...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <excludes>
            ????

        </excludes>
    </configuration>
</plugin>

有没有办法用编译器插件来捣乱?或者我应该去个人资料?我觉得创建一个配置文件是矫枉过正,但可能这是唯一的解决方案……

编辑:

我们已经确定配置文件是解决方案.对于pom.xml中的条件激活,可以使用以下命令:

<profiles>
  <profile>
    <activation>
      <property>
        <IncludeMayBe>true</IncludeMayBe>
      </property>
    </activation>
    ...
  </profile>
</profiles>
最佳答案
我建议你使用 Build helper maven plugin.
使用它,您可以拥有多个源目录.
然后,您可以使用配置文件控制包含的源目录.

假设您在src / monitoring / java下有监控类,可以将以下内容添加到pom.xml中的元素中

<profiles>
    <profile>
        <id>monitoring</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.5</version>
                    <executions>
                        <execution>
                            <id>add-sources</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>${basedir}/src/monitoring/java</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
点击查看更多相关文章

转载注明原文:java – 在maven项目中从编译中有条件地排除文件 - 乐贴网