Excluding generated-sources from source:jar

浪尽此生 提交于 2019-12-23 11:01:19

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/21536283/excluding-generated-sources-from-sourcejar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!