javamavenjarmaven-source-plugin

Exclude packages while generating sources jar in Maven


I would like to generate a sources jar but without some packages in my project.

Now I have this in my 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>

How to exclude specific packages?

similar but with netbeans environment


Solution

  • You can configure the maven-source-plugin with the excludes attribute:

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

    A sample configuration where you would exclude every class under the package com.my.package would be the following:

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