Hi all,

I'm trying to customize my Maven deploying tasks.

Here's what I would like to do in one task:

Generate the WAR file, generate the sources of the WAR project (including 
WEB-INF) and the sources of the depending project sources, upload to maven all 
3 jar files (2 sources and WAR file).
Depending on command line arguments, the WAR release (and WAR source) could 
have a classifier.
I wish to block the release, if it's not a SNAPSHOT and the dependencies 
contains a SNAPSHOT.

I can do some of the things, but I'm stuck with others. I'll post all my work, 
so people can criticize if I'm too far from best practice, and give ideas to 
people having the same needs.

Root gradle:

subprojects {

    usePlugin 'java'
    version '2.2.0.DEV13-SNAPSHOT'

    task sourcesJar(type: Jar) {
        from sourceSets.main.allSource
        // wont work because of GRADLE-704
        classifier = 'sources'
    }
}

WAR gradle:

task initConfiguration << {
    // creates a ConfigSlurper containing all kinds of settings if an 
environment was set as a command line parameter.
    deployConfig = // whatever
}

war.doFirst {
    if (project.hasProperty('deployConfig') {
        // wont work because of GRADLE-704
        war.classifier = deployconfig.environment

        // Do some other things on the war
    }
}

sourcesJar {
    // How can I add the default WEB-INF directory to my sources?
}

artifacts {
    archives war
    archives sourcesJar
}

uploadArchives {
    repositories.mavenDeployer {
        configuration = configurations.release // when I will need to deploy 
using WEB-DAV, configuration called 'release' is declared.
        repository(url: 'file://d:/erwan-dev/tmp/REPO')
        snapshotRepository(url: 'file://d:/erwan-dev/tmp/REPO-SNAPSHOT')
    }
}

def isSnapshotDependent() {
    def containsSnapshot = false
    // TODO I want to run the following only if i am releasing on the main repo.
    // should I check the presence of the string 'SNAPSHOT' in the projects 
version? How does the maven plugin knows that I'm uploading a SNAPSHOT or a 
main version?
    configurations.default.allDependencies.each { dep ->
        if (dep.version.indexOf('SNAPSHOT') > 0)
            containsSnapshot = true
    }
    return containsSnapshot
}

task release(dependsOn: initConfiguration)  << {
    // check that i'm not depending on a SNAPSHOT
    if (isSnapshotDependent()) {
        throw new GradleException("cannot release since dependencies contains a 
SNAPSHOT")
    }
    uploadArchives.execute() // is there a bug? Executing the task with the 
command line runs the 'war' task. Executing the same command from another task 
will not launch the 'war' task.

    // unless a parameter says NO
    uploadSources.execute() // knowing that I would wish for both this project 
and the "service" project sources to be uploaded. Maybe 
ServiceProject.uploadSources.execute() ?
}


As you see, I'm a little stuck until issue 704 is fixed (I will DL the latest 
trunk version soon).
My main concern is to create a task that will launch the 'uploadArchives' task. 
As I explained in a comment, right now launching 'uploadArchives' from another 
task wont trigger the 'war' task. Maybe this is a bug. I could get away from 
that by including the dependency manually of my custom task on 'war' and 
'sourcesJar' tasks.
I wish there was an easy way to detect that a library version is a SNAPSHOT, 
including my own project.

The documentation on Maven plugin is, how to say, evasive. Maybe I could post 
this draft on the wiki, so the community can bring their experience to it?

Thanks in advance for the community help,
Erwan

Reply via email to