How to exclude jar and publication task from root project in multi-project structure

Hi,

My gradle project is multi-project structure. It consist two subprojects.
I write a build.gradle in root project as following:

allprojects {
	apply plugin: 'eclipse'
}

subprojects {
	apply plugin: 'java'
	apply plugin: 'maven-publish'

	publishing {
		repositories {
			maven {
				name 'myMaven'
				def suffix = project.version.endsWith("SNAPSHOT") ? "snapshots" : "releases"
				url baseUrl + suffix
			}
		}
		publications {
			core(MavenPublication) {
				artifactId project.name
				artifact jar
			}		
		}
	}
}

project(':root:projectA') {
	ext {
		sharedManifest = manifest {
		   	attributes("Implementation-Title": project.name,
						"Implementation-Version": 1.0 )
		}
	}
	jar {
		manifest = project.manifest {
	        from sharedManifest
	    }    
	}
}
project(':root:projectB') {
	ext {
		sharedManifest = manifest {
		   	attributes("Implementation-Title": project.name,
						"Implementation-Version": 2.0 )
		}
	}
	jar {
		manifest = project.manifest {
	        from sharedManifest
	    }    
	}
}

It will product 3 jars: root.jar, projectA.jar and projectB.jar. Then they are all be published to my local maven repository.

The question is that I don’t want to produce the root.jar, how to prevent to generate it and not publish to repository.
Because the root project is the empty folder without any source codes, it just a multi-project maintainer for me. It SHOULD not be produce any artifact.

Any suggestion or guide is welcome.

Thank you in advance.

Sincerely,
Micky

What does your settings.gradle look like?

my settings.gradle

include 'root:projectA'
include 'root:projectB'

project(":root:projectA").projectDir = new File("projectA/")
project(":root:projectB").projectDir = new File("projectB/")

the project directory structure

root
|--build.gradle
|--settings.gradle
|--projectA
    |--src/
    |--build.gradle
|--projectB
    |--src/
    |--build.gradle

Have you tried just:

include 'projectA', 'projectB'

‘root:projectA’ ends up creating a “root” subproject that’s different from the “root project” that everything is relative to.

Thanks, actually I use it before:

include 'projectA', 'projectB'

but when integration build, I create a ‘integration’ gradle project to include the ‘root’ project and ‘sample’ project.

The ‘sample’ project is the client project to use the ‘root’ project API in the development phase.
So this is multi-project gradle setting to include another multi-project gradle setting.

The integration project’s build.gradle:

project(':sample') {
	dependencies {
		compile project(':root:projectA')
		compile project(':root:projectB')
	} 
}

and the settings.gradle of integration project is:

rootProject.name = "integration"

include 'root'
include 'root:projectA'
include 'root:projectB'
include 'sample'

project(":root").projectDir = new File("../root")
project(":root:projectA").projectDir = new File("../root/projectA")
project(":root:projectB").projectDir = new File("../root/projectB")
project(":sample").projectDir = new File("../sample")

and the integration, root, and sample project are flat multi-project as following:

/
--root
  |--build.gradle
  |--settings.gradle
--integration
  |--build.gradle
  |--settings.gradle
--sample
  |--build.gradle

That’s why I need to use setting.gradle in root project as

include 'root:projectA'
project(":root:projectA").projectDir = new File("projectA/")

Any suggestion for my multi-project directory structure?

Anyway I will try to use the suggestion you mentioned above, and back to tell if it works or not.

Thanks!!

Not sure it help you, because you’re using standard publication plugin.
But I’m using com.vanniktech.maven.publish plugin and I just tell gradle to not apply it to the root project via following snippet:

plugins {
    id "com.vanniktech.maven.publish" version "0.18.0" apply false
}

After this, empty jar disappeared from publications.