在 Maven 中生成源 jar 时排除包

Exclude packages while generating sources jar in Maven

我想生成源 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

您可以配置 maven-source-plugin with the excludes 属性:

List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.

一个示例配置,其中您将排除包 com.my.package 下的每个 class 如下:

<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>