带有多模块的 Artifactory 发布 gradle

Artifactory publish with multi-module gradle

希望一切顺利。

今天我正在研究多模块 gradle 项目,并试图将其中一个依赖项也发布到 artifactory

我的项目结构是:

build.gradle (main)

buildscript {
    ext {
        appVersion = "0.0.2-RC3"
        appBuildCode = 2

        // dependencies version
        springVersion = "2.6.0"

        swaggerApiVersion = "1.5.12"
        jjwtVersion = "0.11.2"
        lombokVersion = "1.18.22"

        // firebase versions
        firebaseAdminVersion = "8.1.0"
    }

    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springVersion")
        classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.2.0")
        classpath("io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE")
        classpath("org.jfrog.buildinfo:build-info-extractor-gradle:latest.release")
    }
}

apply(plugin: "org.sonarqube")
apply(plugin: "jacoco")

allprojects {
    apply(plugin: 'java')
    apply(plugin: 'org.springframework.boot')
    apply(plugin: 'io.spring.dependency-management')


    group 'com.example'

    repositories {
        mavenCentral()

        maven {
            url "${artifactory_contextUrl}/libs-release/"
            allowInsecureProtocol true
        }
    }

    configurations {
        all*.exclude module: 'spring-boot-starter-logging'
    }

    dependencies {
    ....
    }
}

build.gradle (api)

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'com.jfrog.artifactory'
}

version "${appVersion}"

artifactory {
    contextUrl = artifactory_contextUrl

    publish {
        contextUrl = artifactory_contextUrl

        repository {
            repoKey = artifactory_repoKey
            username = artifactory_user
            password = artifactory_password
        }

        defaults {
            publishConfigs('published')
            publishIvy = false
            publications("mavenJava")
        }
    }
}

//jar {
//////    archiveName 'admin-api.jar'
//////    manifest{
//////        attributes ("Fw-Version" : "2.50.00", "${parent.manifestSectionName}")
//////    }
//////    baseName 'admin-api'
////    archivesBaseName = "$archivesBaseName"
//
//    from {
//        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
//    }
//}

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

artifacts {
    archives sourcesJar
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from(components.java)
//            artifactId = 'admin-api'

            artifact(sourcesJar) {
                classifier 'sources'
            }
        }
    }
}


task dist(type: Zip, dependsOn: build) {
    classifier = 'buildreport'

    from('build/test-results') {
        include '*.xml'
        into 'tests'
    }

    from('build/reports/codenarc') {
        into 'reports'
    }

    from('build/docs') {
        into 'api'
    }

    from(sourcesJar) {
        into 'source'
    }

    from('build/libs') {
        exclude '*-sources.jar'
        into 'bin'
    }
}

//artifactoryPublish.dependsOn('clean', 'build', 'groovydoc', 'sourcesJar', 'dist')
//publish.dependsOn(artifactoryPublish)

and the task artifactoryPublish produces:

> Task :admin-api:extractModuleInfo
[pool-7-thread-1] Deploying artifact: http://10.0.0.3:8081/artifactory/libs-release-local/com/example/admin-api/0.0.2-RC3/admin-api-0.0.2-RC3-plain.jar
[pool-7-thread-1] Deploying artifact: http://10.0.0.3:8081/artifactory/libs-release-local/com/example/admin-api/0.0.2-RC3/admin-api-0.0.2-RC3.module
[pool-7-thread-1] Deploying artifact: http://10.0.0.3:8081/artifactory/libs-release-local/com/example/admin-api/0.0.2-RC3/admin-api-0.0.2-RC3.pom
> Task :artifactoryDeploy

现在的问题是,

模块,如admin-api构建名称为admin-api-0.0.2-RC3-plain.jar,在另一个项目中解析依赖失败,需要使用此API报告以下问题:

Could not resolve com.example.admin-api:0.0.2-RC3.
Required by:
    project :admin-api

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

gradle依赖声明:

dependencies {
    compileOnly('com.example:admin-api:0.0.2-RC3')
}

请帮助我解决这里的问题。

此外,他们是否有任何方法可以使模块 jar 构建时没有后缀 -plain

提前致谢:)

您好,我终于使用以下配置实现了这一点:

allprojects {    
    ....
    bootJar {
        enabled = false
    }
    
    jar {
        archiveClassifier.convention('')
        archiveClassifier.set('')
    }
    ....
}