【问题标题】:Maven assembly plugin attach sources of dependenciesMaven 程序集插件附加依赖源
【发布时间】:2016-02-26 20:40:30
【问题描述】:

一些开源许可证要求分发每个依赖项的原始代码。我需要将提取的源代码提供给我的 Maven 程序集插件。

如何递归获取每个使用的单个依赖项的所有源 JAR?

dependency:sources 仅将源依赖项下载到本地 Maven 存储库,而不是我需要定义的自定义目录。

【问题讨论】:

  • 这是不可能的。如果您依赖一个代码不公开的专有库怎么办?
  • 当然,如果源不能通过 maven 获得,这将不起作用。但他们中的大多数是。正如我在帖子中所说,我只是在谈论开源组件。
  • 顺便说一下,dependency:sources 解析了项目所有依赖项的源(包括传递的)。所以我不确定你为什么说它不是递归的。
  • 你提到的目标有一个参数“outputFile” - 这不是你需要它做的吗?见:maven.apache.org/plugins/maven-dependency-plugin/…
  • 不,它没有,OutputFile 指定了某种 logFILE 而不是目录。

标签: java maven


【解决方案1】:

找到解决方案:

                   <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.9</version>
                        <executions>
                            <execution>
                                <id>get-dependency-sources</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${sources.directory}</outputDirectory>
                                    <classifier>sources</classifier>
                                    <prependGroupId>true</prependGroupId>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

结合

               <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.7</version>
                    <executions>
                        <execution>
                            <id>unpack-sources</id>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <target>
                                    <move todir="${sources.directory}">
                                          <fileset dir="${sources.directory}">
                                            <include name="**/*.jar"/>
                                        </fileset>
                                        <mapper type="glob" from="*.jar" to="*.zip"/>
                                    </move>
                                </target>

                            </configuration>
                        </execution>
                        ...

首先收集${sources.directory} 中的所有资源,然后将 jar 重命名为 zip 文件(这使“普通”用户能够在 Windows 资源管理器中查看其内容。 或者,您也可以使用unzip ANT 任务直接解压缩 jar。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 2014-04-25
    • 2016-05-14
    • 2015-06-28
    • 2016-03-12
    • 1970-01-01
    • 2014-12-02
    • 2010-12-23
    相关资源
    最近更新 更多