Building a dynamic deploy script

Hi,

I’m trying to build a gradle script that pulls in a specific version or SNAPSHOT from artifactory based on a command line variable. -Pdt=release or -Pdt=snapshot {default}

Based on the ‘dt’ parameter, it would either get from libs-release-local or libs-snapshot-local which we deploy to.

My problem seems to be that I cannot define the repoUrl before hand and I cannot define it afterwards as artifactory.

This is a bit messy since I was just testing but you’ll get the general idea of where I am:

configurations{
        deploy
}

def repoUrl = "http://127.0.0.1:8081/artifactory/"
def finalUrl = ""

if (project.hasProperty('dt')) {
        println "dt = ${dt}"
        if (!(dt.equalsIgnoreCase('release') || (dt.equalsIgnoreCase('snapshot')
))) {
                println "*****************************************"
                println "* dt must either be release or snapshot *"
                println "*****************************************"
                System.exit(0)
        } else {
                finalUrl = repoUrl + 'libs-release-local'
                if (dt.equalsIgnoreCase('snapshot')) {
                        finalUrl = repoUrl + 'libs-snapshot-local'
                }
        }
} else {
        println "**************************************"
        println "* Please tell us the deployment type *"
        println "* by using -Pdt=release,snapshot     *"
        println "**************************************"
        System.exit(0)
}

repositories {
        maven { url ${finalUrl} }
}

dependencies{
        deploy 'com.test.myApp:+''
}

task deploy (type:Copy) {
        from configurations.deploy
        into "/opt/myApp/lib"
}

task clean << {
        println "In Local Clean..."
        def dirs = ["lib"]
        dirs.each {
                delete it
        }
}

Try with
url “${finalUrl}”

That’s something close to what we do for your ivy repositories, so it’s definitely something that you can achieve

Yup, that was it.

Odd thing though, as soon as I switch to this, my POM files now have the ‘+’ version wildcard entries rather than resolved versions of the dependencies. I did see a bunch of bug-report for gradle 2.2 which seems to have been fixed but I’m still seeing this in 2.3. I even tried upgrading the wrapper for 2.5 to see if that would fix it, and 2.5 is also doing it.

I can’t upgrade the jfrog plugin to 3.1.1 since that breaks a bunch of other things.

publishing { 
                    publications { 
                            mavenJava (MavenPublication) {
                                    pom.withXml {
                                        def dependenciesNode = asNode().getAt('dependencies')[0]
                                        configurations.runtime.allDependencies.each {
                                                if(!it.name.endsWith("-ws")) {
                                                        def dependencyNode = dependenciesNode.appendNode('dependency')
                                                        dependencyNode.appendNode('groupId', it.group)
                                                        dependencyNode.appendNode('artifactId', it.name)
                                                        dependencyNode.appendNode('version', it.version)
                                                }
                                        }
                                    }
                                    from components.java
                                    artifact sourceJar
                            }
                    }
            }

Your pom.withXml{} call seems ok to me.

MavenPublishPlugin and IvyPublishPlugin are still incubating, and with the refactoring going on right now for the rule based mechanism and the dependency resolution engine, I guess they’re not top priority.