How to use maven ant task from gradle?

I am trying to publish some artifacts in a central maven repo, and since the current version of gradle (0.9-rc2) does not handle pgp, I would try to "port" the ant xml version from https://docs.sonatype.org/display/Repository/Sonatype+ OSS + Maven + Repository + Usage + Guide , expecting gradle 1.0, which I hope will support it out of the box ...

I wrote the following in gradle:

def mvn = groovy.xml.NamespaceBuilder.newInstance(ant, 'antlib:org.apache.maven.artifact.ant') mvn.mvn { arg(value: 'org.apache.maven.plugins:maven-gpg-plugin:1.1:sign-and-deploy-file') arg(value: '-Durl=file:///tmp/repo2') arg(value: '-DrepositoryId=sonatype-nexus-staging') arg(value: '-DpomFile=pom.xml') arg(value: '-Dfile=myjar.jar') arg(value: '-Dfile=-Pgpg') } 

Unfortunately, it does not work, and I get the following:

 Cause: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:mvn Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any <presetdef>/<macrodef> declarations have taken place. No types or tasks have been defined in this namespace yet 

I tried various combinations, including adding the following to my script:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'org.apache.maven:maven-ant-tasks:2.1.1' } } 

Any help would be greatly appreciated

Thanks yang

+7
maven groovy gradle
source share
1 answer

I did not find a way to use NamespaceBuilder, but I found another way to use the task directly, which solves my problem:

 repositories { mavenCentral() } configurations { mavenAntTasks } dependencies { mavenAntTasks 'org.apache.maven:maven-ant-tasks:2.1.1' } task hello << { ant.taskdef(resource: 'org/apache/maven/artifact/ant/antlib.xml', uri: 'antlib:org.apache.maven.artifact.ant', classpath: configurations.mavenAntTasks.asPath) ant.mvn(...) } 
+7
source share

All Articles