So, after a lot of trying, I was able to produce the following results
Project structure
test-java-multiproject
|- test-java-multiproject-api
\- test-java-multiproject-app
declaring build.gradle in test-java-multiproject-api
like this
plugins {
id 'java-library'
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.11'
}
and in test-java-multiproject-app
like this
plugins {
id 'java'
}
dependencies {
compile project(':test-java-multiproject-api')
testCompile ('junit:junit:4.13')
}
working example
using build.gradle in main project like this
buildscript {
repositories {
maven { url this.getAt('repositoryDependency') }
}
}
allprojects {
apply plugin:'maven-publish'
configurations {
deployerJars
}
dependencies {
deployerJars "org.apache.maven.wagon:wagon-ssh:2.2"
}
publishing {
publications {
maven(org.gradle.api.publish.maven.MavenPublication) {
groupId = project.group
artifactId = project.name
version = project.version
if (project.plugins.hasPlugin('java')) {
from components.java
}
if (project.plugins.hasPlugin('spring-boot')) {
pom {
parent {
groupId "org.springframework.boot"
artifactId "spring-boot-starter-parent"
version "${project.versions.springBoot}"
}
}
}
}
}
repositories {
maven {
def repositoryReleases
def repositorySnapshots
repositoryReleases = project.hasProperty('repositoryReleases')
? project.getAt('repositoryReleases')
: 'http://localhost:8081/artifactory/libs-releases-local'
repositorySnapshots = project.hasProperty('repositorySnapshots')
? project.getAt('repositorySnapshots')
: 'http://localhost:8081/artifactory/libs-snapshots-local'
url = project.version.endsWith('SNAPSHOT')
? repositorySnapshots
: repositoryReleases
credentials {
credentials {
username project.getAt('artifactoryUsername')
password project.getAt('artifactoryPassword')
}
}
}
}
}
repositories {
maven {
url this.getAt('repositoryDependency')
}
}
}
subprojects {
version = '1.0'
}
using any task - inclusing publish - works as intended.
broken example
Changing the main buld.gradle to
apply plugin: 'my-plugin'
buildscript {
repositories {
maven { url this.getAt('repositoryDependency') }
}
dependencies {
classpath("my:plugin:0.9.9-SNAPSHOT")
}
}
allprojects {
repositories {
maven {
url this.getAt('repositoryDependency')
}
}
}
subprojects {
version = '1.0'
}
and applying my-plugin
, which looks llike this:
class UploadPlugin implements Plugin<Project> {
void apply(Project project) {
project.allprojects.each { curProject ->
curProject.afterEvaluate{
if(curProject.plugins.hasPlugin(JavaPlugin)){
applyUpload(curProject)
}
}
}
}
void applyUpload(Project project){
project.plugins.apply('maven-publish')
project.configurations { deployerJars }
project.dependencies { deployerJars "org.apache.maven.wagon:wagon-ssh:2.2" }
def canUpload = project.hasProperty('uploadable')
project.publishing {
publications {
maven(org.gradle.api.publish.maven.MavenPublication) {
groupId = project.group
artifactId = project.name
version = project.version
if (project.plugins.hasPlugin('java')) {
from components.java
}
if (project.plugins.hasPlugin('spring-boot')) {
pom {
parent {
groupId "org.springframework.boot"
artifactId "spring-boot-starter-parent"
version "${project.versions.springBoot}"
}
}
}
}
}
if (canUpload) {
repositories {
maven {
def repositoryReleases
def repositorySnapshots
repositoryReleases = project.hasProperty('rel')
? project.getAt(rel)
: 'url1'
repositorySnapshots = project.hasProperty('sna')
? project.getAt('sna')
: 'url2'
url = project.version.endsWith('SNAPSHOT')
? repositorySnapshots
: repositoryReleases
}
}
}
}
}
}
consistently leads to the following build fail when using
gradle clean assemble test
* What went wrong:
A problem occurred configuring project ':test-java-multiproject-api'.
> Could not get unknown property 'components' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
As far as I know, both situations should be roughly the same. The plugin was compiled with the same version as the current project is being executed.
If I ever find out how to package the plugin itself with the project and apply it, I will gladly provide it, however right now I’d have to release the entire plugin which I am definitely not allowed to do.
If this helps anyone in reproducing and helping, please tell me. Thanks a lot in advance.