Skip to content
Advertisement

Artifactory publish with multi-module gradle

Hope all doing well.

Today I was working on multi-module gradle project, and trying to publish one of it’s dependency to artifactory as well.

my project structure are:

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

Now the issue is that,

the modules, like admin-api builds with the name admin-api-0.0.2-RC3-plain.jar, and the resolution of dependency fails in another project, from which this API needs to be used by reporting following issue:

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 dependency statement:

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

Please assist me on what is going wrong here.

Also, is their any way so that the modules jar builds without the suffix -plain?

Thanks in advance:)

Advertisement

Answer

Hi finally I’ve achieved this using the following configurations:

allprojects {    
    ....
    bootJar {
        enabled = false
    }
    
    jar {
        archiveClassifier.convention('')
        archiveClassifier.set('')
    }
    ....
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement