如何使用 gradle 中的 Maven ant 任务?

发布于 2024-09-30 16:59:12 字数 1330 浏览 5 评论 0原文

我正在尝试将一些工件发布到 Maven 中央存储库,并且由于当前版本的 gradle (0.9-rc2) 不处理 pgp 我想我可以通过“移植”ant xml 版本,同时等待 gradle 1.0,希望它能开箱即用地支持它。

我在 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')
  }

不幸的是它不起作用,我得到了这个:

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

我尝试了各种组合,包括在脚本顶部添加以下内容:

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

任何帮助将不胜感激,

谢谢 严

I am trying to publish some artifacts to the maven central repo and since the current version of gradle (0.9-rc2) does not handle pgp I thought I would give it a try by 'porting' the ant xml version while waiting for gradle 1.0 which hopefully 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 is not working and I am getting this:

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 have tried various combinations including adding the following at the top of my script:

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

Any help would be much appreciated

Thanks
Yan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-10-07 16:59:12

我没有找到使用 NamespaceBuilder 的方法,但我找到了另一种能够直接使用任务来解决我的问题的方法:

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(...)
}

I did not find a way to use NamespaceBuilder but I found another way to be able to use the task directly which solves my issue:

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(...)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文