Search code examples
javagradlebuild.gradlegradle-pluginmaven-bom

Parent gradle module with java-platform plugin


I have the following build.gradle file:

plugins {
    id 'maven-publish'
    id 'java-platform'
}
subprojects {
    configurations {
        deployerJars
    }

    apply plugin: 'java'
    apply plugin: 'java-library'
}
publications {
    myPlatform(MavenPublication) {
        from components.javaPlatform
    }
    mavenJava(MavenPublication) {
        from components.java
    }
}

And i'm receiving that error:

> Could not get unknown property 'javaPlatform' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

Couldn't find any information about this error, and from what I understand from the platform plugin page, you cannot set a project with 'java' plugin a 'java-platform' plugin, but this is not the case. I'd appreciate some guidance here, thanks.


Solution

  • publications must be inside the publishing block. And you can't use from components.java since your project isn't a Java project, but a platform. So it should be

    plugins {
        id 'maven-publish'
        id 'java-platform'
    }
    subprojects {
        configurations {
            deployerJars
        }
    
        apply plugin: 'java'
        apply plugin: 'java-library'
    }
    publishing {
        publications {
            myPlatform(MavenPublication) {
                from components.javaPlatform
            }
        }
    }