# Java-gradle-plugin seems incompatible with maven-publish

**URL:** <https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [August 10, 2016, 12:07am UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878 "2016-08-10T00:07:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ned\_Twigg](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ned_twigg/32/1516_2.png) [@Ned\_Twigg](https://discuss.gradle.org/u/Ned_Twigg)\
**Post date:** [August 10, 2016, 12:07am UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/1 "2016-08-10T00:07:09Z")

</div>

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

```gradle
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`?

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [August 10, 2016, 7:14am UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/2 "2016-08-10T07:14:51Z")

</div>

Try

```
publishing.publications.pluginMaven.pom.withXml {...}
```

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [August 10, 2016, 7:42am UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/3 "2016-08-10T07:42:46Z")

</div>

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

> [@Adding custom artifacts to an existing publication](https://discuss.gradle.org/t/adding-custom-artifacts-to-an-existing-publication/18067):
>
> I have a very simple plugin project whose Gradle script looks like this apply plugin: 'groovy' apply plugin: 'maven-publish' apply plugin: 'java-gradle-plugin' group='com.company.project' version='1.0.0-SNAPSHOT' defaultTasks 'clean', 'build' dependencies { compile localGroovy() } task packageSources(type: Jar) { classifier = 'sources' from sourceSets.main.allSource } publishing { repositories { maven { url "${buildDir}/local-repository" } } } When I run “gradlew c…

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [August 10, 2016, 10:18am UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/4 "2016-08-10T10:18:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ned\_Twigg](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ned_twigg/32/1516_2.png) [@Ned\_Twigg](https://discuss.gradle.org/u/Ned_Twigg)\
**Post date:** [August 10, 2016, 6:07pm UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/5 "2016-08-10T18:07:47Z")

</div>

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

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

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

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

publishing.publications.pluginMaven.pom.withXml {}

```

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [August 10, 2016, 6:20pm UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/6 "2016-08-10T18:20:14Z")

</div>

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.

```gradle
model {
    publishing {
        publications {
            pluginMaven {
                ...
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Ned\_Twigg](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ned_twigg/32/1516_2.png) [@Ned\_Twigg](https://discuss.gradle.org/u/Ned_Twigg)\
**Post date:** [August 10, 2016, 6:36pm UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/7 "2016-08-10T18:36:51Z")

</div>

Thanks @st_oehme and @Chris_Dore for the help! All fixed now. Might be nice if [the java-gradle-plugin docs](https://docs.gradle.org/current/userguide/javaGradle_plugin.html) 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.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [August 10, 2016, 7:05pm UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/8 "2016-08-10T19:05:10Z")

</div>

> [@Ned\_Twigg](#):
>
> afaik it’s the easiest way to use testKit

Could you elaborate on this?

---

<div class="post-metadata">

**Author:** ![Ned\_Twigg](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ned_twigg/32/1516_2.png) [@Ned\_Twigg](https://discuss.gradle.org/u/Ned_Twigg)\
**Post date:** [August 10, 2016, 7:22pm UTC](https://discuss.gradle.org/t/java-gradle-plugin-seems-incompatible-with-maven-publish/18878/9 "2016-08-10T19:22:32Z")

</div>

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.
