Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle's publishToMavenLocal task is not executed correctly

I'm trying to create a gradle based multi-module project. There is also an project that contains different gradle scripts that enables pluggable build configurations. One of those scripts is for publishing artifacts to maven repository. This is the content of that script:

apply plugin: 'maven-publish'

configure(subprojects.findAll()) {
    if (it.name.endsWith('web')) {
        publishing {
            publications {
                mavenWeb(MavenPublication) {
                    from components.web
                }
            }
        }
    } else {
        publishing {
            publications {
                mavenJava(MavenPublication) {
                    from components.java
                }
            }
        }
    }
}

build.dependsOn publishToMavenLocal

This script is included in the build gradle file of other project.

apply from: '../../food-orders-online-main/artifact-publish.gradle'

When I run build task it always shows that publishToMavenLocal task is up to date and I cannot find the artifacts in the local repository. Am I doing something wrong?

like image 250
Rade Milovic Avatar asked Oct 26 '14 20:10

Rade Milovic


People also ask

What is publishToMavenLocal?

The publishToMavenLocal is a built-in task of the maven-publish plugin of Gradle, and it will not publish anything into the remote Artifactory (JCenter / Maven) at all. In the project where you are integrating the Library: Add mavenLocal() as a repository location in the main build.gradle.


2 Answers

By adapting answer from here, it works for me.

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
    repositories {
        mavenLocal()
    }
}
like image 135
heading Avatar answered Sep 20 '22 11:09

heading


I think this could be a manifestation of a bug with gradle, that modules can lose the publishMavenJavaPublicationToMavenLocal task when they are depended upon in a certain way.

If gradle determines that there is no publishMavenJavaPublicationToMavenLocal task for a module then the publishToMavenLocal task will always report that it is up to date.

The specific case I have found occurs in a multimodule setup, with multiple levels of nested modules. It can be summarised as follows, where shared:domain loses its publishMavenJavaPublicationToMavenLocal when depended upon by A

root
root gradle build file
->A
  own gradle build file with dependency on shared:domain
-> shared
    gradle build file for shared modules
     -> shared:domain
     -> shared:B

I have created a small example project demonstrating this behaviour available here - https://github.com/piersy/Gradle2MavenPublishBug

I have also logged a bug with gradle here - http://forums.gradle.org/gradle/topics/the-publishmavenjavapublicationtomavenlocal-task-disappears-from-a-project-when-that-project-is-depended-upon-in-a-specific-way

For now the workarounds I have found are to

  1. Remove A's dependency on shared:domain
  2. Make A a submodule with its configuration specified in its parent module build file
  3. Give shared:domain its own gradle build file
like image 43
PiersyP Avatar answered Sep 22 '22 11:09

PiersyP