使用gradle将源上载到nexus存储库

gll*_*mbi 21 java nexus gradle

我使用maven插件成功地将我的罐子上传到nexus存储库,但它没有上传源代码.这是我的配置:

uploadArchives {
    repositories{
        mavenDeployer {
            repository(url: "http://...") {
                 authentication(userName: "user", password: "myPassword")
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我搜索并发现我可以通过添加新任务来添加源.

task sourcesJar(type: Jar, dependsOn:classes) {
     classifier = 'sources'
     from sourceSets.main.allSource
}

artifacts {
     archives sourcesJar
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我认为必须有一个更好的解决方案,通过配置maven插件,像uploadSource = true这样:

uploadArchives {
    repositories{
        mavenDeployer {
            repository(url: "http://...") {
                 authentication(userName: "user", password: "myPassword")
            }
            uploadSources = true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Seb*_*ebi 8

没有比你自己描述的更好的解决方案了.gradle maven插件正在上载当前项目中生成的所有工件.这就是你必须明确创建"源"工件的原因.

使用新的maven-publish插件时,情况也不会改变.在这里,您还需要明确定义其他工件:

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact sourceJar {
                classifier "sources"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

原因是gradle更多地是作为一般构建工具而不是纯Java项目的约束.


Edd*_*dez 5

您可以使用gradle-nexus-plugin

要使用该插件,请添加以下行并导入插件

buildscript {
     repositories {
         mavenLocal()
         jcenter {
            url "http://jcenter.bintray.com/"
        }
     }
     dependencies {
         classpath 'com.bmuschko:gradle-nexus-plugin:2.3'
     }
 }

apply plugin: 'com.bmuschko.nexus'
Run Code Online (Sandbox Code Playgroud)

添加此部分,您将在其中配置要部署的url

nexus {
     sign = false
     repositoryUrl = 'http://localhost:8081/nexus/content/repositories/releases/'
     snapshotRepositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal-snapshots/'
 }
Run Code Online (Sandbox Code Playgroud)

注意:您必须具有〜/ .gradle/gradle.properties

nexusUsername = deployment
nexusPassword = deployment123
Run Code Online (Sandbox Code Playgroud)

  • 一个好的答案应该包括所有相关信息,而不是链接到外部资源:"如果目标站点无法访问或永久脱机,请始终引用重要链接的最相关部分." (4认同)