gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:31:04 25 4
gpt4 key购买 nike

我需要将一个外部 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 forargument 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com