Gradle Publish does not upload files to the Nexus repository (Maven 2)

Asked

Viewed 31 times

0

I’m trying to get my project to send the Jars files to a Nexus (Maven 2) repository but I’m not getting it. The project is programmed in Kotlin.

This code fragment is as close as I could get to a result:

plugins {
     id 'maven'
}

allprojects {
    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "http://meusite.com/repository/meurepo-releases/") {
                    authentication(userName: variavelComUser, password: variavelComPass)
                }

                snapshotRepository(url: "http://meusite.com/repository/meurepo-snapshots/") {
                    authentication(userName: variavelComUser, password: variavelComPass)
                }
            }
        }
    }
}

When I execute the task publish this occurs:

20:02:07: Executing task 'uploadArchives'...

> Task :uploadArchives
> Task :environment:core:compileJava NO-SOURCE
> Task :environment:core:compileKotlinCommon
> Task :environment:core:processResources NO-SOURCE
> Task :environment:core:classes
> Task :environment:core:inspectClassesForKotlinIC
> Task :environment:core:jar
> Task :environment:core:uploadArchives
> Task :environment:js:compileJava NO-SOURCE
> Task :environment:js:compileKotlin2Js
> Task :environment:js:processResources NO-SOURCE
> Task :environment:js:classes
> Task :environment:js:inspectClassesForKotlinIC
> Task :environment:js:jar
> Task :environment:js:uploadArchives
> Task :environment:jvm:compileKotlin
> Task :environment:jvm:compileJava NO-SOURCE
> Task :environment:jvm:processResources NO-SOURCE
> Task :environment:jvm:classes UP-TO-DATE
> Task :environment:jvm:inspectClassesForKotlinIC
> Task :environment:jvm:jar
> Task :environment:jvm:uploadArchives

BUILD SUCCESSFUL in 14s

But when I access the Nexus I see nothing there, it’s still empty.

What I’m doing wrong or what’s missing?

1 answer

0


The problem is that the block uploadArchives was not being applied to all projects as it seemed.

As my root project was just a container of other subprojects I solved in this way:

subprojects {
    afterEvaluate {
        if (it.plugins.hasPlugin('maven') ) {
            uploadArchives {
                repositories {
                    mavenDeployer {
                        repository(url: "http://meusite.com/repository/meurepo-releases/") {
                            authentication(userName: varComUser, password: varComSenha)
                        }

                        snapshotRepository(url: "http://meusite.com/repository/meurepo-snapshots/") {
                            authentication(userName: varComUser, password: varComSenha)
                        }
                    }
                }
            }
        }
    }
}

Watching we see 3 important changes:

  1. I traded allprojects for subprojects since my root project has no source code.
  2. I inserted the block afterEvaluate to run the block after the first settings are ready in all sub-modules.
  3. I added a check if you have the plugin Maven before putting the uploadArchives and put applied the plugin in all modules I want to export to the Nexus, and with it I took the block id maven block plugins root module.

This way I managed to get each module sent to the Nexus individually.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.