在Maven中生成源jar时排除包

时间:2016-03-09 16:38:31

标签: java maven jar maven-source-plugin

我想在我的项目中生成一个源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

1 个答案:

答案 0 :(得分:2)

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

  

要排除的文件列表。指定为相对于其内容被打包到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>