在 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项目中有条件地从编译中排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6025596/