【问题标题】:Exclude packages while generating sources jar in Maven在 Maven 中生成源 jar 时排除包
【发布时间】:2016-06-24 04:07:04
【问题描述】:

我想生成一个源 jar,但我的项目中没有一些包。

现在我的 pom.xml 中有这个

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>sources</id>
                    <goals>
                        <goal>jar</goal>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

如何排除特定的包?

similar but with netbeans environment

【问题讨论】:

    标签: java maven jar maven-source-plugin


    【解决方案1】:

    您可以使用excludes 属性配置maven-source-plugin

    要排除的文件列表。指定为文件集模式,这些模式与将其内容打包到 JAR 中的输入目录相关。

    您将排除 com.my.package 包下的每个类的示例配置如下:

    <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>sources</id>
                <goals>
                    <goal>jar</goal>
                    <goal>test-jar</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                    <excludes>
                        <exclude>com/my/package/**</exclude>
                    </excludes>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

    • 不排除我定义的包;像com.my.package/**这样定义包有问题吗
    • @jam 是的,这是个问题,您需要使用斜杠,因为它们指的是磁盘上的文件。
    猜你喜欢
    • 2011-05-06
    • 2023-03-05
    • 2012-04-11
    • 2018-12-14
    • 2012-04-05
    • 2018-04-01
    • 2011-01-27
    • 2018-08-13
    • 1970-01-01
    相关资源
    最近更新 更多