Using the maven plugin for non java artefacts

I have a some non java artefacts, generally tarballs, that are published to nexus and produced by the build. As far as I can see, the ‘MavenPlugin’ only does the following;

  • configures an install task for projects that have applied the Java plugin

  • configures an upload task for projects that have applied the Base plugin

Is this correct? i.e. all I need to do to be able to upload an arbitrary artefact is ensure the BasePlugin is applied (and wire up the configuration etc as usual)?

Why is “install” java specific ?

Cheers Matt

Is this correct? i.e. all I need to do to be able to upload an arbitrary artefact is ensure the BasePlugin is applied (and wire up the configuration etc as usual)?

Yep.

Why is “install” java specific ?

It’s a “bug”. That is, it shouldn’t be this way.

OK thanks. Will the bug be filed in your JIRA (as per the recent post on this)? In the meantime, is there any other solution apart from cut and paste the code from the mavenplugin into my own build?

It’s now linked to GRADLE-2427. The best solution for now is good ol’ copy paste.

Hi Luke or Matt,

Could you possibly provide a few more details on what a copy/paste from the maven plugin work-around would look like? I would also like to use the Maven plugin to install/publish artifacts from a non-java project to maven repos and/or local caches.

It seems this issue is also related to (or outright duplicates) these issues (and there may be others):

GRADLE-2134 GRADLE-2125

Regards,

Doug

My configuration of the cpp plugin is as follows

@Override
    void doPreEvaluationConfig() {
        // BasePlugin is applied otherwise maven doesn't work properly
        project.apply(plugin: BasePlugin)
        if (project.library.type.plugin != null)
            project.apply(plugin: project.library.type.plugin)
        // cpp-lib doesn't provide a build task which our release plugin expects
        DefaultTask buildTask = project.tasks.add(JavaBasePlugin.BUILD_TASK_NAME, DefaultTask)
        buildTask.description = 'Assembles this project.'
        buildTask.group = BasePlugin.BUILD_GROUP;
        buildTask.dependsOn(project.tasks.compileMain)
        // setup the artefacts for uploading
        project.artifacts {
            archives project.libraries.main.spec.outputFile
        }
        // ensure sonar skips it
        project.sonar.project.skip = true
        mavenize()
    }
      @Override
    void doPostEvaluationConfig() {
        // no op
    }
      void mavenize() {
        // have to add an install task ourselves for the CPP plugin
        Upload installUpload = project.tasks.add('install', Upload.class)
        installUpload.group = 'Upload'
        Configuration configuration = project.configurations.getByName(Dependency.ARCHIVES_CONFIGURATION)
        installUpload.configuration = configuration
        MavenRepositoryHandlerConvention repositories = new DslObject(installUpload.repositories).convention.getPlugin(MavenRepositoryHandlerConvention.class)
        repositories.mavenInstaller({doPomCustomisation(pom)});
        installUpload.setDescription("Does a maven install of the archives artifacts into the local .m2 cache.");
    }

my setup has a project applying our own ‘LibPlugin’ for anything that produces artefacts and it then declares what type of lib it is (java, groovy, etc). The pre/post bit is code called when the plugin is applied or after the projects have been evaluated. Most of the code above is cut/paste from existing gradle plugins.