How can I get rev and revConstraint for dynamic dependency in published ivy.xml Gradle build

I have a question about publishing Ivy in Gradle.

From Ivy, I expect that if I publish an artifact, for example, with this dependency:

<dependency org="org.apache.ant" name="ant" rev="1+"/>

My published ivy.xml gets both a fixed and a dynamic version:

<dependency org="org.apache.ant" name="ant" rev="1.9.6" revConstraint="1+"/>

I want this also in Gradle. I have Gradle 2.10.

Here is my Gradle project:

apply plugin: "java"

group = 'org.wibble'
version = "1.2.3"

repositories {
    mavenCentral()
}

dependencies {
  compile group: 'org.apache.ant', name: 'ant', version: '1+' // resolves to version 1.9.6 at the time of writing
}

uploadArchives.repositories {
  ivy { name "testrepo"; url "$buildDir/testrepo" }
}

If I run gradle uploadArchives, then the resulting ivy.xml has the following:

<dependency org="org.apache.ant" name="ant" rev="1+" conf="compile-&gt;default"/>

In the Gradle source code, I see that there is a means to write rev and revConstraint:

if (!dep.getDynamicConstraintDependencyRevisionId().equals(dependencyRevisionId)) {
    <...>
    writer.attribute("revConstraint", dep.getDynamicConstraintDependencyRevisionId().getRevision());
}

With debugging, I also see that this code is hit, but in my case both getDynamicConstraintDependencyRevisionId and dependencyRevisionId give '1+' at this stage, and version 1.9.6 is forgotten at this stage.

, , ivy.xml, Ivy?

+4
1

, . . , - . RaGe Pom gradle .

, , - , gradle, rev, revConstraint. rev "latest.release", . rev revConstraint last.release.

publishing {
publications {
    ivyJava(IvyPublication) {            
        from components.java
        configurations.create('sources')
        artifact(sourceJar) {
            type "source"
            conf "sources"
            classifier "sources"
        }
        configurations.create('javadoc')
        artifact(javadocJar) {
            type "javadoc"
            conf "javadoc"
            classifier "javadoc"
        }
        descriptor {
            withXml {
                if (project.configurations.findByName("runtime") != null) {
                    Map resolvedVersionMap = [:]
                    Configuration runtimeConfiguration = project.configurations.getByName('runtime')
                    ResolutionResult resolution = runtimeConfiguration.incoming.resolutionResult
                    resolution.getAllComponents().each { ResolvedComponentResult versionResult ->
                        resolvedVersionMap.put("${versionResult.moduleVersion.group}:" +
                                ":${versionResult.moduleVersion.name}", versionResult.moduleVersion.version)
                    }

                    asNode().dependencies.dependency.each { dep ->
                        if ("latest.release".equalsIgnoreCase(dep.@rev) || "latest.integration".equalsIgnoreCase(dep.@rev)
                                || "latest.snapshot".equalsIgnoreCase(dep.@rev)) {
                            dep.@revConstraint = dep.@rev
                            dep.@rev = resolvedVersionMap.get("${dep.@org}:" +
                                    ":${dep.@name}")
                            dep.@changing = "true"
                        }
                    }
                }
            }
        }
    }
}

}

0

Source: https://habr.com/ru/post/1624116/


All Articles