首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用gradle下载/使用已发布的工件

如何使用gradle下载/使用已发布的工件
EN

Stack Overflow用户
提问于 2020-05-27 04:36:44
回答 1查看 214关注 0票数 0

我正在尝试将工件发布到私有-GitLab,其中包含两个依赖项(Web和Actuator),如下所示

代码语言:javascript
复制
dependencies {
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-web")

}
repositories {
    maven {
        url "https://<gitlab-url>/repo"
        name "GitLab"
        credentials(HttpHeaderCredentials) {
            name = 'Private-Token'
            value = gitLabPrivateToken
        }
        authentication {
            header(HttpHeaderAuthentication)
        }
    }
}

但不确定我是否面临401错误。我用本地目录替换了git,它成功了。我可以看到生成的元数据和pom文件。在使用build.gradle下面的另一个项目使用本地目录中的工件时

代码语言:javascript
复制
buildscript {
    repositories {
        mavenCentral()
         maven {
            url "C://<location>//gradle-test"
        }
    }
    dependencies {
        classpath("com.gradle:gradleproject:0.0.1-SNAPSHOT")
    }
}

我正面临以下错误。

代码语言:javascript
复制
C:\Users\root\gradle>gradle build

> Task :buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

classpath
\--- com.gradle:gradleproject:0.0.1-SNAPSHOT
     +--- org.springframework.boot:spring-boot-starter-actuator:2.3.0.RELEASE
     |    +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE
     |    |    +--- org.springframework.boot:spring-boot:2.3.0.RELEASE
     |    |    |    +--- org.springframework:spring-core:5.2.6.RELEASE
     |    |    |    |    \--- org.springframework:spring-jcl:5.2.6.RELEASE
     |    |    |    \--- org.springframework:spring-context:5.2.6.RELEASE
     |    |    |         +--- org.springframework:spring-aop:5.2.6.RELEASE
     |    |    |         |    +--- org.springframework:spring-beans:5.2.6.RELEASE
     |    |    |         |    |    \--- org.springframework:spring-core:5.2.6.RELEASE (*)
     |    |    |         |    \--- org.springframework:spring-core:5.2.6.RELEASE (*)
     |    |    |         +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
     |    |    |         +--- org.springframework:spring-core:5.2.6.RELEASE (*)
     |    |    |         \--- org.springframework:spring-expression:5.2.6.RELEASE
     |    |    |              \--- org.springframework:spring-core:5.2.6.RELEASE (*)
     |    |    +--- org.springframework.boot:spring-boot-autoconfigure:2.3.0.RELEASE
     |    |    |    \--- org.springframework.boot:spring-boot:2.3.0.RELEASE (*)
     |    |    +--- org.springframework.boot:spring-boot-starter-logging:2.3.0.RELEASE
     |    |    |    +--- ch.qos.logback:logback-classic:1.2.3
     |    |    |    |    +--- ch.qos.logback:logback-core:1.2.3
     |    |    |    |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
     |    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.13.2
     |    |    |    |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
     |    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.13.2
     |    |    |    \--- org.slf4j:jul-to-slf4j:1.7.30
     |    |    |         \--- org.slf4j:slf4j-api:1.7.30
     |    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
     |    |    +--- org.springframework:spring-core:5.2.6.RELEASE (*)
     |    |    \--- org.yaml:snakeyaml:1.26
     |    +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.3.0.RELEASE
     |    |    +--- org.springframework.boot:spring-boot-actuator:2.3.0.RELEASE
     |    |    |    \--- org.springframework.boot:spring-boot:2.3.0.RELEASE (*)
     |    |    +--- org.springframework.boot:spring-boot:2.3.0.RELEASE (*)
     |    |    +--- org.springframework.boot:spring-boot-autoconfigure:2.3.0.RELEASE (*)
     |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.11.0
     |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0
     |    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.11.0
     |    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.0
     |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0
     |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.11.0
     |    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
     |    |    +--- org.springframework:spring-core:5.2.6.RELEASE (*)
     |    |    \--- org.springframework:spring-context:5.2.6.RELEASE (*)
     |    \--- io.micrometer:micrometer-core:1.5.1
     |         +--- org.hdrhistogram:HdrHistogram:2.1.12
     |         \--- org.latencyutils:LatencyUtils:2.0.3
     \--- org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE
          +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
          +--- org.springframework.boot:spring-boot-starter-json:2.3.0.RELEASE
          |    +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
          |    +--- org.springframework:spring-web:5.2.6.RELEASE
          |    |    +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
          |    |    \--- org.springframework:spring-core:5.2.6.RELEASE (*)
          |    +--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
          |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.0
          |    |    +--- com.fasterxml.jackson.core:jackson-core:2.11.0
          |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
          |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.0 (*)
          |    \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.0
          |         +--- com.fasterxml.jackson.core:jackson-core:2.11.0
          |         \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
          +--- org.springframework.boot:spring-boot-starter-tomcat:2.3.0.RELEASE
          |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
          |    +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.35
          |    +--- org.glassfish:jakarta.el:3.0.3
          |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.35
          |         \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.35
          +--- org.springframework:spring-web:5.2.6.RELEASE (*)
          \--- org.springframework:spring-webmvc:5.2.6.RELEASE
               +--- org.springframework:spring-aop:5.2.6.RELEASE (*)
               +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
               +--- org.springframework:spring-context:5.2.6.RELEASE (*)
               +--- org.springframework:spring-core:5.2.6.RELEASE (*)
               +--- org.springframework:spring-expression:5.2.6.RELEASE (*)
               \--- org.springframework:spring-web:5.2.6.RELEASE (*)

(*) - dependencies omitted (listed previously)

有人能帮我在哪里犯错误或如何解决这个错误吗?这是正确的消费方式吗?

EN

回答 1

Stack Overflow用户

发布于 2020-05-27 04:51:27

下面的示例演示如何对Java库(包括源、Javadoc和自定义POM)进行签名和发布:

build.gradle

代码语言:javascript
复制
plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

group = 'com.example'
version = '1.0'

java {
    withJavadocJar()
    withSourcesJar()
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifactId = 'my-library'
            from components.java
            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }
            pom {
                name = 'My Library'
                description = 'A concise description of my library'
                url = 'http://www.example.com/library'
                properties = [
                    myProp: "value",
                    "prop.with.dots": "anotherValue"
                ]
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'johnd'
                        name = 'John Doe'
                        email = 'john.doe@example.com'
                    }
                }
                scm {
                    connection = 'scm:git:git://example.com/my-library.git'
                    developerConnection = 'scm:git:ssh://example.com/my-library.git'
                    url = 'http://example.com/my-library/'
                }
            }
        }
    }
    repositories {
        maven {
            // change URLs to point to your repos, e.g. http://my.org/repo
            def releasesRepoUrl = "$buildDir/repos/releases"
            def snapshotsRepoUrl = "$buildDir/repos/snapshots"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
    }
}

signing {
    sign publishing.publications.mavenJava
}


javadoc {
    if(JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
}

其结果是将发布以下工件:

  • POM:my-library-1.0.pom
  • Java组件的主JAR工件:my-library-1.0.jar
  • 已显式配置的源JAR工件:my-library-1.0-sources.jar
  • 已显式配置的Javadoc工件:my-library-1.0-javadoc.jar

签名插件用于为每个工件生成一个签名文件。此外,将为所有工件和签名文件生成校验和文件。

请参阅此链接:

maven.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62035560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档