I had problems getting it to work when using the maven-publish plugins. The sub-projects artifacts ended up being published with version = unspecified which haunted me for over an hour.
I managed to get it to work by specifically configure the version and group in a sub-project closure or by adding a apply from: ‘…/build.gradle’ in each sub-project.
Which one is “best practice”?
Coming from Maven the apply from: '…/build.gradle feels most “right”.
PS. Ignore the duplications…
Layout:
myApp/
build.gradle
settings.gradle
subA/
build.gradle
subB
build.gradle
myApp/build.gradle:
group = 'com.example'
version = '1.0.0-SNAPSHOT'
subprojects {
group = 'com.example'
version = '1.0.0-SNAPSHOT' // "best practice"?
}
... common stuff ...
myApp/settings.gradle:
rootProject.name = 'myApp'
include 'subA', 'subB'
myApp/subA/build.gradle:
apply from: '../build.gradle' // "best practice"?
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
sourceCompatibility = 1.7
targetCompatibility = 1.7
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
myApp/subB/build.gradle:
apply from: '../build.gradle' // "best practice"?
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
publishing {
publications {
mavenWar(MavenPublication) {
from components.web
}
}
}