Duplicate但没有答案,也无法评论
背景信息:我有一个模块使用 xmlbeans-maven-plugin 从 xsd 生成 java 源文件并编译到它自己的 jar 中。这有效并且还创建了一个包含 java 源的 module1/target/generated-sources 文件夹。该模块已构建,但在 jar 中生成了源,这是不必要的,因为 xmlbeans 插件创建了一个单独的 jar 来保存编译生成的源
我正在尝试排除 target/generated-sources 目录被打包到模块的 jar Artifact 中。我尝试在 maven-compiler-plugin 和 maven-jar-plugin 中使用 target/generated-sources/xmlbeans/noNamespace/**/*.java 但没有成功
我在这里错过了什么?
这是模块的 pom.xml,如果需要父 pom,我也会发布:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>parent</artifactId>
<groupId>parent</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>workflow</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>WorkFlow processing App</name>
<build>
<finalName>workflow</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
<outputJar>${build.dir}/lib/WorkflowResponse.jar</outputJar>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>${compiler.source.version}</source>
<target>${compiler.target.version}</target>
<generatedSourcesDirectory>target</generatedSourcesDirectory>
<!--<includes>-->
<!--<include>src/main/java/**/*.java</include>-->
<!--</includes>-->
<excludes>
<exclude>target/generated-sources/xmlbeans/noNamespace/**/*.java</exclude>
</excludes>
</configuration>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-jar-plugin</artifactId>-->
<!--<version>2.4</version>-->
<!--<configuration>-->
<!--<includes>-->
<!--<include>src/main/java/com/company/appname/*.java</include>-->
<!--</includes>-->
<!--</configuration>-->
<!--</plugin>-->
</plugins>
</build>
****更新******
我已经设法排除了生成的源,但它很难看且不可移植:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<includes>
<include>com/**</include>
</includes>
</configuration>
</plugin>
这将只包括 target/classes/com 下的内容,编译完成后,当 maven 将模块打包到一个不干净的 jar 中时。理想情况下,排除应该发生在编译器中,这样 target/generated-sources 的内容就不会编译到 target/classes/
最佳答案
与您在更新中使用 includes 的方式类似,有一个 excludes 元素可以满足您的需求。您只需指出要排除而不是包含的包。
http://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html
关于java - Maven:从 jar Artifact 中排除生成的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24067295/