Excluding generated-sources from source:jar

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>

Answers


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>

Need Your Help

Another one concerning array adapters (android)

android loops arraylist android-arrayadapter android-spinner

I have an ArrayAdapter being populated with ints from a while loop, we will say from 3 to 18. These numbers are put into a Spinner.

PHP Regex on CD Tracklists

php regex preg-match

I'm using preg_match to format tracklists so the track number, title and duration are separated into their own cells in a table: