How do I place the POM generated from the maven-publish plugin inside the jar?

I am trying out FUSE bundles (http://fuse.fusesource.org/bundle/faq.html). To use them, I have to place the POM for a jar inside the jar in the directory: “META-INF/maven/groupId/artifactId/pom.xml”

How would I go about placing the pom generated by that plugin inside the jar at the location described by the groupID/artifactID that was put in the pom?

Thanks

1 Like

Assuming your publication is named ‘main’, the following should work. You may have to adapt ‘groupId’ and ‘artifactId’ as needed.

jar {
    into("META-INF/maven/$project.group/$project.name") {
        from generatePomFileForMainPublication
        rename ".*", "pom.xml"
    }
}
1 Like

I thought it was something like that, but I get this (the publication is mavenJava):

  • What went wrong: A problem occurred evaluating project ‘:example’. > No such property: generatePomFileForMavenJavaPublication for class: org.gradle.api.internal.file.copy.CopySpecImpl_Decorated

This might be related to the new configuration approach used for the ‘maven-publish’ plugin. I recommend to try with the latest nightly build.

Ok, I will give that a shot when I come in tomorrow. Thanks for the replies! :slight_smile:

Still doesn’t work with the nightly.

$ gr :example:clean :example:jar
Parallel execution with configuration on demand is an incubating feature.
  FAILURE: Build failed with an exception.
  * Where:
Build file 'C:\path\to\example\build.gradle' line: 3
  * What went wrong:
A problem occurred evaluating project ':example'.
> No such property: generatePomFileForMavenJavaPublication for class: org.gradle.api.internal.file.copy.DefaultCopySpec_Decorated
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED
  Total time: 5.898 secs
  $ gr --version
  ------------------------------------------------------------
Gradle 1.9-20131003220019+0000
------------------------------------------------------------
  Build time:
 2013-10-03 22:00:19 UTC
Build number: none
Revision:
   7970ec3503b4f5767ee1c1c69f8b4186c4763e3d
  Groovy:
     1.8.6
Ant:
        Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:
        2.2.0
JVM:
        1.7.0_21 (Oracle Corporation 23.21-b01)
OS:
         Windows 7 6.1 amd64

Here is the jist of my build script (The line number will not match with above because this is actually a multiproject build with some of this in 'subprojects sections of the main build.gradle)

apply plugin: 'maven-publish'
  publishing {
    publications {
         mavenJava(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            credentials {
                username snapshot_user
                password snapshot_password
            }
            url nexus_snapshot_url
         }
    }
}
  jar {
    into("META-INF/maven/$project.group/$project.name") {
        from generatePomFileForMavenJavaPublication
        rename ".*", "pom.xml"
    }
}
  dependencies {
    testCompile "junit:junit:4.0"
}

Have you verified that you can run ‘gradle generatePomFileForMavenJavaPublication’?

Yes, and it generates the pom I would expect. I did notice this in the documentation:

The “maven-publish” plugin leverages some experimental support for late plugin configuration, and any GenerateMavenPom tasks will not be constructed until the publishing extension is configured. The simplest way to ensure that the publishing plugin is configured when you attempt to access the GenerateMavenPom task is to place the access inside a publishing block, as the above example demonstrates.

Do I have to wrap this jar part in a publishing block? Would that even work?

I guess it would.

I tried wrapping the jar part in a publishing block, did not help, same error.

Raised GRADLE-2916. A workaround is to hard-code the path and add an explicit task dependency (‘dependsOn “generatePomFileForMavenJavaPublication”’).

1 Like

Great, the workaround will do for now. Thanks! :slight_smile: