Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle deploy artifacts to a maven repository inside a local directory

Tags:

maven

gradle

What is Gradle's equivalent of Maven's:

<distributionManagement>
    <repository>
        <id>internal.repo</id>
        <name>Temporary Staging Repository</name>
        <url>file://${project.build.directory}/mvn-repo</url>
    </repository>
</distributionManagement>

<build>
 <plugins>
    <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
               <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
        </configuration>
    </plugin>
 </plugins>
</build>

I have tried:

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file:///tmp/mvn-repo")
        }
    }
}

but it throws:

[ant:null] Error reading settings file '/private/var/folders/KH/KH+cubLjEESWzOTqVrx-bU+++TI/-Tmp-/gradle_empty_settings7564764539012703872.xml' - ignoring. Error was: /private/var/folders/KH/KH+cubLjEESWzOTqVrx-bU+++TI/-Tmp-/gradle_empty_settings7564764539012703872.xml (No such file or directory)

The project that I am working on is git://github.com/SpringSource/spring-data-rest.git branch 1.0.0.RELEASE, project's build.gradle.

Complete Gradle output:

gradle uploadArchives
The groovy configuration has been deprecated and is scheduled to be removed in Gradle 2.0. Typically, usages of 'groovy' can simply be replaced with 'compile'. In some cases, it may be necessary to additionally configure the 'groovyClasspath' property of GroovyCompile and Groovydoc tasks.
:uploadArchives
[ant:null] Error reading settings file '/private/var/folders/KH/KH+cubLjEESWzOTqVrx-bU+++TI/-Tmp-/gradle_empty_settings396071803108301794.xml' - ignoring. Error was: /private/var/folders/KH/KH+cubLjEESWzOTqVrx-bU+++TI/-Tmp-/gradle_empty_settings396071803108301794.xml (No such file or directory)
:spring-data-rest-core:compileJava UP-TO-DATE
:spring-data-rest-core:compileGroovy UP-TO-DATE
:spring-data-rest-core:processResources UP-TO-DATE
:spring-data-rest-core:classes UP-TO-DATE
:spring-data-rest-core:jar UP-TO-DATE
:spring-data-rest-core:javadoc UP-TO-DATE
:spring-data-rest-core:javadocJar UP-TO-DATE
:spring-data-rest-core:sourcesJar UP-TO-DATE
:spring-data-rest-core:uploadArchives
:spring-data-rest-repository:compileJava UP-TO-DATE
:spring-data-rest-repository:compileGroovy UP-TO-DATE
:spring-data-rest-repository:processResources UP-TO-DATE
:spring-data-rest-repository:classes UP-TO-DATE
:spring-data-rest-repository:jar UP-TO-DATE
:spring-data-rest-repository:javadoc UP-TO-DATE
:spring-data-rest-repository:javadocJar UP-TO-DATE
:spring-data-rest-repository:sourcesJar UP-TO-DATE
:spring-data-rest-repository:uploadArchives
:spring-data-rest-webmvc:compileJava UP-TO-DATE
:spring-data-rest-webmvc:compileGroovy UP-TO-DATE
:spring-data-rest-webmvc:processResources UP-TO-DATE
:spring-data-rest-webmvc:classes UP-TO-DATE
:spring-data-rest-webmvc:jar UP-TO-DATE
:spring-data-rest-webmvc:javadoc UP-TO-DATE
:spring-data-rest-webmvc:javadocJar UP-TO-DATE
:spring-data-rest-webmvc:sourcesJar UP-TO-DATE
:spring-data-rest-webmvc:uploadArchives

I use Gradle 1.12.

like image 295
Adam Siemion Avatar asked Jun 03 '14 08:06

Adam Siemion


People also ask

How do I deploy Gradle build artifacts to Maven?

Gradle - Deployment. Gradle offers several ways to deploy build artifacts repositories. When deploying signatures for your artifacts to a Maven repository, you will also want to sign the published POM file. Using the Maven-publish Plugin. maven-publish plugin, which is provides by Gradle by default.

What is Gradle repository in Maven?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.

What are artifacturls used for in Gradle?

If the JAR can’t be found there, the extra artifactUrls are used to look for JARs. You can specify credentials for Maven repositories secured by different type of authentication. See Supported repository transport protocols for authentication options. Gradle can consume dependencies available in the local Maven repository .

Does Gradle require publishing credentials to publish artifacts?

If for example a project is configured to publish artifacts to a secured repository, but the build does not invoke publishing task, Gradle will not require publishing credentials to be present.


2 Answers

If you are trying to deploy locally (e.g. to ~/.m2) then you need:

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            mavenLocal()
        }
    }
}

I haven't tried using a repository in anything other than the default but I believe you can either set the repository location in ~/.m2/settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
  http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>/tmp/mvn_repo</localRepository>
  ...
</settings>

or you can set the url in the gradle build file:

maven {
     url uri('/tmp/mvn_repo')
} 
like image 97
mikea Avatar answered Nov 02 '22 11:11

mikea


Found the cause of the problem. The project I am building is a multi module project, here I have found this information:

52.6.4.1. Multiple artifacts per project

Maven can only deal with one artifact per project. This is reflected in the structure of the Maven POM. We think there are many situations where it makes sense to have more than one artifact per project. In such a case you need to generate multiple POMs. In such a case you have to explicitly declare each artifact you want to publish to a Maven repository.

So I have moved uploadArchives from the root level build.gradle to a project level build.gradle and this fixed the issue.

I think the error message regarding maven's setting.xml is very misleading and should be fixed by the Gradle team.

like image 24
Adam Siemion Avatar answered Nov 02 '22 11:11

Adam Siemion