Using the output of a task in configuring a publication using maven-publish

Hi, I’m trying to use the maven-publish plugin to publish an artifact with a custom pom. The actual artifact is being generated from a source folder that is also a git repository. I’m using the gradle-git plugin and the GitLog task to extract the commit id that corresponds to the source zip. My publication snippet looks like this

publishing {
    repositories distConfig
      publications {
        sourcePkg(MavenPublication) {
            artifact source: sourceZip, classifier: "src", extension: "zip"
              pom.withXml {
                asNode().appendNode('scm').appendNode('tag', new File("$buildDir/$versionClassifier").text )
            }
        }
    }
}

I am attempting to configure the pom to put in the git commit id in the pom.scm.tag element. I have created a custom task of type GitLog, that parses the last commit id and saves it into a file

task gitLog(type: GitLog) {
    repoPath = "${gitDependenciesDir}/${project.name}"
    maxCommits = 1
    doLast {
        versionFile = new File("$buildDir/$versionClassifier")
        log.each {
            versionFile.write( it.abbreviatedId )
        }
    }
}

When i run something like “gradle publishToMavenLoca”, i am getting an error that the file is not there since it seems the eneratePomFileForSourcePkgPublication task is being called before my GitLog task.

Can someone provide some insight into how i can take the output of the GitLog task and save it somehow so that i can use it in the publication to configure my pom?

Don’t you just need to add a task dependency on ‘gitLog’?

That’s what i’m trying to do. I tried to do

tasks.publishToMavenLocal.dependsOn('gitLog')

but that doesn’t seem to do anything. Also it is unclear as to how i can actually manipulate the tasks added by the maven-publish plugin.

I have the sourcePkg task which is a MavenPublication, depend on my sourceZip task which in turn depends on the gitLog task. However when i run 'gradle publishToMavenLocal --info", i get the following execution order

Tasks to be executed: [task ':generatePomFileForSourcePkgPublication', task ':gitLog', task ':gitStatus', task ':sourceZip', task ':publishSourcePkgPublicationToMavenLocal', task ':publishToMavenLocal']

I’m trying to figure out how to manipulate the gradle-publish plugin so that my ‘gitLog’ task runs before the ‘generatePomFileForSourcePkgPublication’ task since the gitLog task generates the information necessary to be included in the pom file.

I’m trying to figure out how to manipulate the gradle-publish plugin so that my ‘gitLog’ task runs before the ‘generatePomFileForSourcePkgPublication’ task

That would be ‘generatePomFileForSourcePkgPublication.dependsOn(gitLog)’. If that blows up, you might have to wrap it in ‘afterEvaluate { … }’.