Question

I'm in the process of building my first custom plugin for gradle. This plugin does a number of things, including configuring the project it's applied to based on other plugins that the project has. One of the things I want this plugin to do is handle all of the Maven publishing work, so that it doesn't need to appear in every build.gradle. Each build does the exact same thing, they just have their source Jar and their base project Jar, and both are (or will be) published to our artifact repository.

That works, I can create the Jar file. However, the Jar file only contains the META-INF folder and manifest file, and none of the classes of the project. Has anyone encountered this problem and know the cause?

   // Configure Jar Manifest
    jar {
        manifest = project.manifest {
            from sharedManifest
        }
    }

    // Configure sources Jar manifest
    (project.getTasks()).create("sourcesJar", Jar) {
        classifier "sources"
        from project.sourceSets.main.allSource
        manifest = project.manifest {
            from sharedManifest
        }
    }

    artifacts {
        archives project.tasks.sourcesJar
    }
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from project.components.java
                artifact project.tasks.sourcesJar
                pom.withXml {
                    def root = asNode()
                    root.appendNode("name", project.name)
                    root.appendNode("description", project.name + "component of company.")
                    root.appendNode("inceptionYear", "2010")
                }
            }
        }
        repositories {
            maven {
                //We only publish to the Releases repository if the project is given the property "release"
                if(project.hasProperty("release")) {
                    url "http://clipped/"
                } else {
                    url "http://clipped/"
                }

                credentials {
                    if(project.hasProperty("nexusUsername") && project.hasProperty("nexusPassword"))
                    {
                        username = nexusUsername
                        password = nexusPassword
                    }
                }
            }
        }
    }
Was it helpful?

Solution

That was it, Peter, a developer had moved all of the projects calling the plugin from src/main/java to src/java, thinking that the folder structure was unnecessarily deep. Nothing wrong with the plugin code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top