加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

groovy – 如何使用gradle中的maven ant任务?

发布时间:2020-12-14 16:32:16 所属栏目:大数据 来源:网络整理
导读:我试图将一些工件发布到maven中央仓库并且因为当前版本的gradle(0.9-rc2)不处理pgp我想我会试着通过’移植’ant xml version同时等待gradle 1.0来尝试希望能够开箱即用. 我在gradle中写了以下内容: def mvn = groovy.xml.NamespaceBuilder.newInstance(ant,
我试图将一些工件发布到maven中央仓库并且因为当前版本的gradle(0.9-rc2)不处理pgp我想我会试着通过’移植’ant xml version同时等待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'
  }
}

任何帮助将非常感激

谢谢

解决方法

我没有找到使用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(...)
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读