Maven:从jar工件中排除生成的源 - java

Duplicate,但没有答案,无法评论

背景信息:我有一个模块,该模块使用xmlbeans-maven-plugin从xsd生成Java源文件并将其编译到其自己的jar中。这可以正常工作,并使用Java源代码创建一个module1 / target / generated-sources文件夹。该模块已构建,但生成的源包含在jar中,这是不必要的,因为xmlbeans插件创建了一个单独的jar,其中包含编译的generate-sources

我试图从打包到模块的jar工件中排除target / generated-sources目录。我尝试在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>

编译之后以及当maven将模块包装到不干净的jar中时,这将仅包含target / classes / com下的内容。理想情况下,排除应该在编译器中进行,这样目标/生成源的内容就不会编译为目标/类/

参考方案

与您在更新中使用include的方式类似,有一个excludes元素可以满足您的需求。您只需指出要排除而不是包括的软件包即可。

http://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html

无法在Maven surefire中运行多个执行? - java

我想运行名称以ResourceTest.java结尾的测试类,因此我在执行后定义了它们。<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <co…

在Maven构建之前如何运行课程? - java

为什么以下原因导致构建失败?我创建了一个应该在maven开始执行构建之前运行的类。 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.5.…

在集成测试阶段执行Maven模块 - java

我想启动一个同级Maven 3模块,该模块在我的一个Maven模块中充当应用程序服务器,以对系统运行集成测试。我的maven项目看起来与此类似:父模块模块A模块B现在,我想在Maven的集成前测试阶段中启动“模块A”,然后运行模块B中包含的所有集成测试。我设法在模块B中运行了集成测试,但是没有找到“光滑”的方法在集成前测试阶段启动模块B。最佳做法是什么?使用…

使用依赖管理访问Maven属性 - java

我正在使用maven的依赖项管理将POM导入到项目Y中,如下所示:<dependencyManagement> <dependencies> <dependency> <groupId>com.abc</groupId> <artifactId>X</artifactId> …

使用play2自动重新加载 - java

这是我的具有maven性质的play2项目:pom.xml以及相关代码:<packaging>play2</packaging> <plugin> <groupId>com.google.code.play2-maven-plugin</groupId> <artifactId>play…