5

Using the source:jar goal, how do I configure it such that the target/generated-sources folder is excluded from the archive? I've tried a number of different configurations, and can't get any of them to work.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.2.1</version>
  <configuration>
    <excludes>
      <exclude>target/generated-sources</exclude>
    </excludes>
  </configuration>
</plugin>

I've tried various things in the exlude tag such as target/generated-sources/**/*.java, com/mycompany/**/*.java and because I became so convinced it wasn't even looking at that, just tried *.java and it seems nothing gets excluded.

This is Maven 3.0.5 and the source plugin 2.2.1. I'm running this from the Maven CLI. Below is the complete POM for those interested.

<?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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>foo-service</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.2.8</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <packageName>com.example</packageName>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <configuration>
          <excludes>
            <exclude>target/generated-sources</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
Colselaw
  • 1,069
  • 9
  • 21

1 Answers1

0

hopefully you figured this out - but for what it's worth. This configuration works to exclude anything in the com.foo.server package and does not include the target folders. Since this runs relative to the src/com directory, your problem may be that your project is configured to put the generated sources in the wrong directory. /target should be next to your /src folder which wouldn't be included in the source plugin, since it would start at /src/main/java/

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <excludes>
                        <exclude>com/foo/server/**</exclude>
                    </excludes>
                </configuration>
                <executions>

                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>

                    </execution>
                </executions>
            </plugin>
bsautner
  • 4,479
  • 1
  • 36
  • 50