I use Gradle 2.4. I have an error I do not understand with a local file system maven repository. What I try to do is to copy from a “ci” repository to a “release” repository. Here is a complete working example of the problem:
settings.gradle
:
rootProject.name = "proj"
build.gradle
:
apply plugin: 'distribution'
project.version = "74384"
ext {
cwd = System.getProperty("user.dir")
ciRepo = cwd+"/ciRepo"
releaseRepo = cwd+"/releaseRepo"
}
buildDir = new File(ext.cwd+"/build")
def docsCopySpec = project.copySpec {
from (cwd) {
include 'file.txt'
}
}
distributions {
docs {
baseName = rootProject.name
contents {
with docsCopySpec
}
}
}
docsDistTar {
compression = Compression.GZIP
classifier = "docs"
}
apply plugin: 'maven-publish'
group = "org.martin"
publishing {
publications {
txt(MavenPublication) {
artifact(docsDistTar) {
classifier "txt"
}
}
}
repositories {
maven {
name "ci"
url ciRepo
}
maven {
name = "release"
url = releaseRepo
}
}
}
task publishTxt() {
dependsOn "publishTxtPublicationToCiRepository"
}
repositories {
maven {
name = "Local file system"
url ciRepo
}
}
configurations {
release
}
dependencies {
release "${group}:${rootProject.name}:${project.version}:txt@tgz"
}
task publishRelease(type: Copy) {
from configurations.release
into releaseRepo
}
To run this code, first create a plain file.txt:
echo "123" > file.txt
Then run:
gradle publishTxt
The local ciRepo
folder contains:
$ tree ciRepo/
ciRepo/
└── org
└── martin
└── proj
├── 74384
│ ├── proj-74384.pom
│ ├── proj-74384.pom.md5
│ ├── proj-74384.pom.sha1
│ ├── proj-74384-txt.tgz
│ ├── proj-74384-txt.tgz.md5
│ └── proj-74384-txt.tgz.sha1
├── maven-metadata.xml
├── maven-metadata.xml.md5
└── maven-metadata.xml.sha1
Now run the publishRelease task:
gradle publishRelease
And:
:publishRelease
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':release'.
> Could not find proj-txt.tgz (org.martin:proj:74384).
...
It looks like the version number is missing from the dependency resolution, but a few minor changes to the build.gradle
file “fix” the problem:
$ diff -u build.gradle build-solved.gradle
--- build.gradle 2015-05-21 19:20:39.918476749 -0400
+++ build-solved.gradle 2015-05-21 19:31:04.562077456 -0400
@@ -9,24 +9,24 @@
}
buildDir = new File(ext.cwd+"/build")
-def docsCopySpec = project.copySpec {
+def txtCopySpec = project.copySpec {
from (cwd) {
include 'file.txt'
}
}
distributions {
- docs {
+ txt {
baseName = rootProject.name
contents {
- with docsCopySpec
+ with txtCopySpec
}
}
}
-docsDistTar {
+txtDistTar {
compression = Compression.GZIP
- classifier = "docs"
+ classifier = "txt"
}
apply plugin: 'maven-publish'
@@ -35,7 +35,7 @@
publishing {
publications {
txt(MavenPublication) {
- artifact(docsDistTar) {
+ artifact(txtDistTar) {
classifier "txt"
}
}
Just those few name changes are enough to “make it work”. Can someone explain to me what I am doing wrong in the first code example, and why such minor changes appear to fix the publishRelease
task?