Java Maven-生成每个依赖项源的存档

Java Maven-生成每个依赖项源的存档,java,maven,dependencies,Java,Maven,Dependencies,有没有一种方法可以将包含每个依赖项源的归档作为一个单独的工件来获取 我知道有一种方法可以使用所述的依赖插件下载每个源jar。但是,这些文件会下载到本地存储库 我努力实现的目标是: 发送一个包含一些可运行代码的JAR。除此之外,还有一个包含JAR中已发布依赖项的源代码的ZIP存档。我需要做一些类似的事情,只是我还需要将包含的源代码过滤到我公司团队生成的源代码中。您可以使用和的组合来实现这一点 这是我使用的配置 <build> <plugins> <plug

有没有一种方法可以将包含每个依赖项源的归档作为一个单独的工件来获取

我知道有一种方法可以使用所述的依赖插件下载每个源jar。但是,这些文件会下载到本地存储库

我努力实现的目标是:


发送一个包含一些可运行代码的JAR。除此之外,还有一个包含JAR中已发布依赖项的源代码的ZIP存档。

我需要做一些类似的事情,只是我还需要将包含的源代码过滤到我公司团队生成的源代码中。您可以使用和的组合来实现这一点

这是我使用的配置

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <configuration>
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>true</overWriteSnapshots>
      </configuration>
      <executions>
        <execution>
          <id>retrieve-dependency-sources</id>
          <phase>process-sources</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <classifier>sources</classifier>
            <outputDirectory>${project.build.directory}/dep-sources</outputDirectory>
            <type>jar</type>
            <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
            <prependGroupId>true</prependGroupId>
            <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
            <excludeTransitive>false</excludeTransitive>
          </configuration>
        </execution>
      </executions>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <executions>
        <execution>
          <id>package-dependency-sources</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <appendAssemblyId>true</appendAssemblyId>
            <attach>true</attach>
            <finalName>${your.app.finalName}</finalName>
            <descriptors>
              <descriptor>src/main/assembly/dep-source-assembly.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
听起来您的用例可能与我的略有不同,因此您可以使用汇编插件来代替单独调用maven依赖插件和文件集

另一个潜在的问题是:如果您是为了war或ear而这样做的,那么您需要在项目的POM上添加一个依赖项,以获得完整的依赖项集。(见附件。)


${my.webapp.groupId}
${my.webapp.artifactId}
${my.webapp.version}
聚甲醛

我需要做一些类似的事情,只是我还需要将包含的源代码过滤到我公司团队制作的源代码中。您可以使用和的组合来实现这一点

这是我使用的配置

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <configuration>
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>true</overWriteSnapshots>
      </configuration>
      <executions>
        <execution>
          <id>retrieve-dependency-sources</id>
          <phase>process-sources</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <classifier>sources</classifier>
            <outputDirectory>${project.build.directory}/dep-sources</outputDirectory>
            <type>jar</type>
            <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
            <prependGroupId>true</prependGroupId>
            <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
            <excludeTransitive>false</excludeTransitive>
          </configuration>
        </execution>
      </executions>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <executions>
        <execution>
          <id>package-dependency-sources</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <appendAssemblyId>true</appendAssemblyId>
            <attach>true</attach>
            <finalName>${your.app.finalName}</finalName>
            <descriptors>
              <descriptor>src/main/assembly/dep-source-assembly.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
听起来您的用例可能与我的略有不同,因此您可以使用汇编插件来代替单独调用maven依赖插件和文件集

另一个潜在的问题是:如果您是为了war或ear而这样做的,那么您需要在项目的POM上添加一个依赖项,以获得完整的依赖项集。(见附件。)


${my.webapp.groupId}
${my.webapp.artifactId}
${my.webapp.version}
聚甲醛
<dependency>
  <groupId>${my.webapp.groupId}</groupId>
  <artifactId>${my.webapp.artifactId}</artifactId>
  <version>${my.webapp.version}</version>
  <type>pom</type>
</dependency>