What if you want to pull from say Sourceforge, Google Projects or a legacy build artifact server ? There used to be a repositories plugin for Gradle, but it no longer seems to work with later Gradle versions. The good news is that it is possible in many cases to achieve this with Ivy + pattern layout.
Ivy usually requires an XML file (Ivy file) to describe its transitive dependencies, but in Gradle if the Ivy file does not exist, then it is simply assumed that there are no transitive dependencies. This is good for working with arbitrary artifact stores as they will not have such files. Managing transitive dependencoes are now up to you, the build script author, but you probably know this anyway as you are already doing something that is not of the ordinary.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
ivy { | |
url 'http://somewhere.example/root' | |
layout ('pattern') { | |
artifact '[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])' | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gradle -btryIt.gradle --info tryIt | |
Starting Build | |
Settings evaluated using empty settings script. | |
Projects loaded. Root project using build file '/home/me/tryIt.gradle'. | |
Included projects: [root project 'me'] | |
Evaluating root project 'me' using build file '/home/me/tryIt.gradle'. | |
Compiling build file '/home/me/tryIt.gradle' using StatementExtractingScriptTransformer. | |
Compiling build file '/home/me/tryIt.gradle' using BuildScriptTransformer. | |
All projects evaluated. | |
Selected primary task 'DefaultTaskParameter{taskName='tryIt',projectPath='null'}' | |
Tasks to be executed: [task ':tryIt'] | |
:hello (Thread[main,5,main]) started. | |
:hello | |
Executing task ':tryIt' (up-to-date check took 0.002 secs) due to: | |
Task has not declared any outputs. | |
Resource missing. [HTTP GET: http://download.sourceforge.net/project/libusb/libusb-1.0/ivy-1.0.19/ivy-1.0.19.xml] | |
Download http://download.sourceforge.net/project/libusb/libusb-1.0/libusb-1.0.19/libusb-1.0.19.tar.bz2 | |
[/home/me/.gradle/caches/modules-2/files-2.1/libusb/libusb/1.0.19/c5d14ced155233ceeb5107c7eb3b94b16649ae05/libusb-1.0.19.tar.bz2] | |
:me (Thread[main,5,main]) completed. Took 4.055 secs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
ivy { | |
url 'http://download.sourceforge.net/project' | |
layout ('pattern') { | |
artifact '[organisation]/[module]-1.0/[artifact]-[revision]/[artifact]-[revision].[ext]' | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
ivy { | |
url 'http://download.sourceforge.net/project' | |
layout ('pattern') { | |
artifact '[organisation]/[module]-1.0/[artifact]-[revision]/[artifact]-[revision].[ext]' | |
} | |
} | |
} | |
configurations { | |
foo | |
} | |
dependencies { | |
foo 'libusb:libusb:1.0.19@tar.bz2' | |
} | |
task tryIt << { | |
println configurations.foo.files | |
} |
To get a better understanding of what these fields mean, I suggest reading the Ivy terminology page. For now let's just see how the standard Mavane items you are familiar with in Gradle will map to these fields.
- group - This maps to organisation.
- artifactId - Effectively maps to both module and artifact. Strictly speaking not the same, but in practice this is usuaaly how it works out.
- version - Maps to revision
- classifier - This seems to be seldom used, is usually optional, but maps to classifier.
- ext - Refers to the extension of the artifact. Is optional and maps to ext.
Notice that the ext field is not in parenthesis, meaning that in this case I expect the extension to be passed.
Finally to prove that it work we can create a little build script tryIt.gradle and running it with gradle --info -b tryIt.gradle tryIt should provide output similar to output.txt.