maven - 使用 gradle 执行 Maven 部署文件

标签 maven gradle groovy deployment build.gradle

我需要将一个外部 zip 文件部署到我的私有(private) Maven 存储库。该文件将包含我的应用程序版本发布,内部存档将包含我的应用程序的文件结构,包括 jars、dll、configs、exes ......

如何使用 gradle 执行 maven deploy:deploy-file?

mvn deploy:deploy-file 
-DgroupId=acme 
-DartifactId=acme 
-Dversion=1.0 
-Dpackaging=jar 
-Dfile=C:\tmp\acme-1.0.jar 
-DrepositoryId=Nexus 
-Durl=http://myserver:8888/nexus/content/repositories/thirdparty/

我正在尝试将外部 zip 文件发布到我的 Maven 存储库:
apply plugin: "base"
apply plugin: "maven"
apply plugin: "maven-publish"

publishing {
    def host = "myhost"
    def url = "http://$host/content/repositories/releases"
    def group = "package"
    def artifact = "name"
    def version = "0.0.1"
    def file = "c:/my.zip"

    publications {
        mavenJava(MavenPublication) {
            create('zip', MavenPublication) {
                groupId "$group"
                artifactId "$artifact"
                version "$version"
                artifact file("$file")
            }       
        }
    }
    repositories {
        maven {
            credentials {
                username 'user'
                password 'pwd'
            }
            url "$url"
        }
    }
}

publish.dependsOn build

但是当它执行时,我得到了这个异常:
FAILURE: Build failed with an exception.

* Where:
Build file 'c:\xxxx\build.gradle' line: 18

* What went wrong:
A problem occurred configuring root project 'XXXXX'.
> Exception thrown while executing model rule: PublishingPlugin.Rules#publishing(ExtensionContainer)
   > No signature of method: java.lang.String.call() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [0.0.1]
Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), take(int), each(groovy.lang.Closure)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

最佳答案

有趣的案例,乍一看并不那么明显。问题是该 block 中的方法( versionartifact ):

mavenJava(MavenPublication) {
  create('zip', MavenPublication) {
     groupId "$group"
     artifactId "$artifact"
     version "$version"
     artifact file("$file")
  }       
}
命名与此 block 中上面几行定义的变量完全相同:
def host = "myhost"
def url = "http://$host/content/repositories/releases"
def group = "package"
def artifact = "name"
def version = "0.0.1"
def file = "c:/my.zip"
这里发生的情况是,在发布 block 版本中,版本被评估为 0.0.1,然后将具有相同值的参数传递给它,它会导致:
"0.0.1"("0.0.1")
它解释了错误消息:

No signature of method: java.lang.String.call() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl)


事实上,第二个参数将是 GString不裸String其次没有call String 上定义的方法groovy 中的类,它接受 String 的实例.
我为所有有问题的名称添加了任何后缀:
apply plugin: "base"
apply plugin: "maven"
apply plugin: "maven-publish"

publishing {
    def host = "myhost"
    def urlWhataver = "http://$host/content/repositories/releases"
    def group = "package"
    def artifactWhatever = "name"
    def versionWhatever = "0.0.1"
    def path = "c:/my.zip"

    publications {
        mavenJava(MavenPublication) {
            create('zip', MavenPublication) {
                groupId "$group"
                artifactId "$artifactWhatever"
                version "$versionWhatever"
                artifact new File("$path")
            }
        }
    }
    repositories {
        maven {
            credentials {
                username 'user'
                password 'pwd'
            }
            url "$urlWhataver"
        }
    }
}

publish.dependsOn build
$path 也有问题转换。

关于maven - 使用 gradle 执行 Maven 部署文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42960927/

相关文章:

java - Maven:找出是在 32 位还是 64 位 JVM 中运行

jenkins - 从 jenkinsfile 执行 groovy 脚本时出现异常 groovy.lang.MissingPropertyException : No such property: args for class: groovy. lang.Binding

java - 从 Maven 调用 groovy 'main' 方法

Javascript 相当于从 Value 创建随机数值

linux - 无法为 Maven 代理端口使用环境变量

java - 自动安装 Eclipse 插件的依赖项

java - 将本地jar添加到mvn clean package结果中

gradle - Gradle:如何在调用task之前参数化/配置变量?

node.js - 在 bundleReleaseJsAndAssets 处生成发布 APK 失败

android - 如何使用 Gradle 动态地从 aar 中排除文件?