Search code examples
scalagradlebuild.gradleartifactoryaws-codebuild

gradle publishing multi module project to AWS Artifact only publishes META-INF


I recently started using gradle and trying to publish a multi module project to AWS Artifact. My build file for submodules looks like below

  1. Module: core
buildscript {

    dependencies {
        classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:0.4.34"
    }
}

plugins {
    id "net.researchgate.release" version "2.8.0"
}


group "com.local"

apply plugin: "java"
apply plugin: "jsonschema2pojo"
apply plugin: "maven"
apply plugin: "net.researchgate.release"

jar {
    baseName "core-schema"
}

release {
    tagTemplate = 'core-${version}'
}

jsonSchema2Pojo {
    source files("${projectDir}/src/main/resources/json")
    generateBuilders = true
}

dependencies {
    compile 'commons-lang:commons-lang:2.6'
    compile 'javax.validation:validation-api:2.0.0.Final'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
}

afterReleaseBuild.dependsOn uploadArchives

  1. spark-example
plugins {
  id 'java'
  id 'java-library'
  id 'scala'
  id 'com.github.johnrengelman.shadow' version '1.2.4'
}

apply plugin: 'scalaStyle'

scalaStyle {
  configLocation = "${project.rootDir}/scalastyle_config.xml"
  includeTestSourceDirectory = true
  source = "src/main/scala"
  testSource = "src/test/scala"
}

dependencies {
  compile group: 'org.apache.spark', name: "spark-core_2.11", version: '2.4.2'
  compile group: 'org.apache.spark', name: "spark-sql_2.11", version: '2.4.2'
}

configurations {
    runtime.exclude module: 'spark-core_2.11'
    runtime.exclude module: 'spark-sql_2.11'
}

compileScala.dependsOn(scalaStyle)

jar {
  mainClassName = 'NONE'
  baseName "spark-sample"
}

tasks.withType(ScalaCompile) {
  ScalaCompileOptions.metaClass.daemonServer = true
  ScalaCompileOptions.metaClass.fork = true
  ScalaCompileOptions.metaClass.useAnt = false
  ScalaCompileOptions.metaClass.useCompileDaemon = false
}

tasks.withType(ScalaCompile) {
  configure(scalaCompileOptions.forkOptions) {
    memoryMaximumSize = '1g'
    jvmArgs = ['-XX:MaxPermSize=512m']
  }
}

And main application build file looks like below:

plugins {
    id 'java-library'
    id 'maven-publish'
}

group "com.local"

subprojects { subproject ->
    configurations {
        deployer
    }

    dependencies {
        deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
    }

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
        maven {
            url "${aws_url}"
            credentials {
                username "aws"
                password System.env.CODEARTIFACT_AUTH_TOKEN
            }
        }

    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = group
            artifactId = artifactName
            version = version
            from components.java
        }
    }
    repositories {
        maven {
            url "${aws_url}"
            credentials {
                username "aws"
                password System.env.CODEARTIFACT_AUTH_TOKEN
            }
        }
    }
}

now when I run gradle build I can see jars getting created for all the modules and root project under corresponding build/libs/ directory with code files. However when I do gradle publish I only see root jar getting published with only MANIFEST.NF file as shown below:

enter image description here

Update:

As suggested by @nico I have tried adding the publishing block in allprojects{} block but it is publishing each project with the root project name and overriding all of them as seen in below log. I have also tried adding the publishing block in subproject like mentioned in this post but still same output.

2030009268:spark-store user$ gradle publishAllPublicationsToMavenRepository

> Task :core:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!

> Task :spark-sample:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!

Updated root project build:

plugins {
    id 'java-library'
    id 'maven-publish'
}

group "com.local"

subprojects { subproject ->
    configurations {
        deployer
    }

    dependencies {
        deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
    }

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
        maven {
            url "${aws_url}"
            credentials {
                username "aws"
                password System.env.CODEARTIFACT_AUTH_TOKEN
            }
        }

    }
}

allprojects {
    apply plugin: 'maven-publish'
    apply plugin: 'java-library'

    publishing {
        publications {
            mavenJava(MavenPublication) {
                groupId = group
                artifactId = artifactName
                version = version
                from components.java
            }
        }
        repositories {
            maven {
                url "${aws_url}"
                credentials {
                    username "aws"
                    password System.env.CODEARTIFACT_AUTH_TOKEN
                }
            }
        }
    }
}

Solution

  • Regarding your main application build file:

    Try including the publishing{} block inside of an allprojects{} block or add it to the above subprojects{} block as well. Currently the publishing-specification is only applied on root-project level.