简体   繁体   中英

Perform a maven deploy-file with gradle

I need to deploy an external zip file to my private maven repository. This file will content my application version release, internally the archive will content the file structure of my application with jars, dlls, configs, exes...

How can I perform a maven deploy:deploy-file using gradle?

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/

I'm trying this to publish an external zip file to my maven repository:

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

But when it execute, I get this exception:

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

Interesting case, not that obvious at the first sight. The problem is that the methods ( version , artifact ) in this block:

mavenJava(MavenPublication) {
  create('zip', MavenPublication) {
     groupId "$group"
     artifactId "$artifact"
     version "$version"
     artifact file("$file")
  }       
}

are named exactly the same as the variables that are defined few lines above in this 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"

What happens here is that in publication block version is evaluated to 0.0.1 and then an argument with the same value is passed to it, it results in:

"0.0.1"("0.0.1")

It explains the error message:

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

In fact the second argument will be GString not bare String and secondly there's no call method defined on String class in groovy which accepts an instance of a String .

I added whatever suffix to all problematic names:

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

There was also a problem with $path conversion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM