
[英]How to upload or deploy multiple versions of an artifact to Sonatype Nexus?
[英]Cannot upload artifact to Nexus Sonatype using Gradle
我正在尝试使用Nexus(版本2.X)作为本地Maven存储库。 我一直在寻找一种方法来自动将我的依赖项上传到Nexus,但我无法让它运行起来。
如果重要的话,使用Gradle 4.1,Java 8和InteliJIdea。
我的build.gradle
文件如下:
group 'myGroupName'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin:'maven'
sourceCompatibility = 1.8
repositories {
maven {
url "http://localhost:8081/nexus/content/repositories/thirdparty/"
}
}
dependencies {
testCompile 'org.testng:testng:6.9.4'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/nexus/content/repositories/thirdparty/") {
authentication(userName: "admin", password: "admin123")
}
}
}
}
我已经上传了commons-math3-3.5.jar
手动,并试图用uploadArchives
上传commons-lang3-3.6
自动。
我得到的错误是
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.apache.commons:commons-lang3:3.6.
Required by:
project :
> Could not resolve org.apache.commons:commons-lang3:3.6.
> Could not get resource 'http://localhost:8081/nexus/content/repositories/thirdparty/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.pom'.
> Could not GET 'http://localhost:8081/nexus/content/repositories/thirdparty/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.pom'. Received status code 401 from server: Unauthorized
我也尝试compile "org.apache.commons:commons-lang3:3.6"
而不是compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
,以便与Nexus匹配构建成绩示例 ,并尝试添加
task wrapper( type: Wrapper, description: "create a gradlew" ) {
gradleVersion = '4.1'
}
但它不起作用。
有谁知道我错过了什么?
没有完整的错误消息,但看起来您在编译阶段遇到错误。 我假设它无法从编译所需的Nexus依赖项下载。 尝试在存储库部分添加jcenter()
来解决它。 或者,您可以在maven配置中为Nexus提供有效凭据
repositories {
maven {
url "http://localhost:8081/nexus/content/repositories/thirdparty/"
credentials {
username "user"
password "password"
}
}
}
我建议也使用maven-publish插件https://docs.gradle.org/current/userguide/publishing_maven.html
顺便说一下,你使用的例子已经过时了。 我建议使用与Gradle捆绑的示例或其文档。
这适合我
buildscript {
repositories {
mavenLocal()
maven {
url "https://www.acme.com/nexus/content/repositories/com.acme.snapshots/"
credentials {
username "admin"
password "admin123"
}
}
maven {
url "https://plugins.gradle.org/m2/"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.