Java-gradle-plugin seems incompatible with maven-publish

So I’ve got a Gradle plugin, which I’ve published for a while like this:

apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'java'
apply plugin: 'maven-publish'

publishing {
    publications {
        mavenJava(MavenPublication) {
            pom.withXml {
                // remove the p2 dependencies because they are embedded
                asNode().dependencies.'*'.each() {
                    if (it.groupId.text() == 'p2') {
                        it.parent().remove(it)
   ....

I have to do some gymnastics to embed some eclipse jars which aren’t available in any public repos.

I tried adopting java-gradle-plugin, and it broke my POM.

Before java-gradle-plugin, my build folder would have publications/mavenJava/pom-default.xml. After java-gradle-plugin, I’ve also got publications/pluginMaven/pom-default.xml, which seems to be the POM which actually gets used, and happens to have wrong stuff (hasn’t been modified by the pom.withXml stuff).

How do I change the POM which gets generated by java-gradle-plugin?

Try

publishing.publications.pluginMaven.pom.withXml {...}
1 Like

See also this post where I suggested creating a model rule instead. I believe both suggestions should work for you.

The java-gradle-plugin automatically creates the publication for you since 2.14. So instead of creating a new one (like you did before), just customize the existing one as @Chris_Dore suggested.

I’m getting Could not get unknown property 'pluginMaven' for Publication container.

Here’s a stripped down build.gradle which reproduces the problem:

plugins {
    id 'com.gradle.plugin-publish' version '0.9.5'
}

apply plugin: 'java-gradle-plugin'
apply plugin: 'maven-publish'

publishing.publications.pluginMaven.pom.withXml {}

Since these publications are currently added by model rules, you’ll have to use the software model to configure them. This will improve in future Gradle versions.

model {
    publishing {
        publications {
            pluginMaven {
                ...
            }
        }
    }
}
1 Like

Thanks @st_oehme and @Chris_Dore for the help! All fixed now. Might be nice if the java-gradle-plugin docs referenced some of this info - I think anyone who is modifying their pom (which means anyone uploading to maven central) and who is using testKit (afaik it’s the easiest way to use testKit) is going to hit this.

Could you elaborate on this?

Sorry, by “its” I mean java-gradle-plugin. If you want to use testkit, you have to do some gymnastics to get your plugin on the classpath, which java-gradle-plugin does for you. When I isolated problems in my pom to the java-gradle-plugin, I figured I’d just go back to plain old apply plugin: 'java'. But then all my testkit tests were failing, so I started to go down the rabbithole of using testkit without java-gradle-plugin, before finally posting here.