A customized solution for use with Artifactory + Ivy + ant
is to scan each module for license information. If the license is found, populate that license file in Artifactory and update it's ivy.xml
to have it available as a published artifact. Then call <ivy:retrieve/>
to fetch the license along with its jar file.
The license can be specified within the module's ivy.xml
as a URL. In this case, use ant
's get
task to download the license and write it to a text file.
[inside log4j's ivy.xml as an example]
<ivy-module xmlns:m="http://ant.apache.org/ivy/maven" version="2.0">
<info organisation="log4j" module="log4j" revision="1.2.16" status="integration"
publication="20120620150430">
<license name="The Apache Software License, Version 2.0"
url="http://www.apache.org/licenses/LICENSE-2.0.txt"/>
...
</info>
</ivy-module>
Alternatively, the license can be included as a text file within the module's .jar
file. In this case, use ant
's unjar
task to extract the license and write it to a text file.
[inside junit's .jar file as an example]
junit-4.8.2.jar/LICENSE.txt
Once the license has been written out as a text file, use ant
's xmltask task to add the license as an artifact.
[inside log4j's ivy.xml as an example]
<publications>
<artifact conf="master" ext="jar" name="log4j" type="bundle"/>
<artifact conf="sources" ext="jar" m:classifier="sources" name="log4j" type="source"/>
<artifact conf="javadoc" ext="jar" m:classifier="javadoc" name="log4j" type="javadoc"/>
<!-- next line added -->
<artifact conf="master" ext="txt" name="log4j" type="license"/>
</publications>
Publish the modified ivy.xml
and the license back to Artifactory.
<ivy:resolve file="${ivy.xml}" />
<ivy:publish resolver="${resolver}" pubrevision="@{rev}" status="integration"
overwrite="true" forcedeliver="true" haltonmissing="false"
srcivypattern="${ivy.local}/[organisation]/[module]/ivy-[revision].xml" >
<artifacts pattern="${ivy.local}/[organisation]/[module]/ivys/ivy-[revision].[ext]" />
<artifacts pattern="${ivy.cache.dir}/[organisation]/[module]/licenses/[module]-[revision].[ext]" />
</ivy:publish>
Use <ivy:retrieve/>
to fetch the license along with its jar file when bundling with your build.
<ivy:retrieve pattern="${ivy.local}/[artifact].[ext]" conf="compile, runtime" type="jar, license" />