
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.
maven-publish plugin, which is provides by Gradle by default. Used to publish the gradle script. Take a look into the following code.
apply plugin: 'java'
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "$buildDir/repo"
}
}
}
There are several publish options, when the Java and the maven-publish plugin is applied. Take a look at the following code, it will deploy the project into a remote repository.
apply plugin: 'groovy'
apply plugin: 'maven-publish'
group 'workshop'
version = '1.0.0'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
default credentials for a nexus repository manager
credentials {
username 'admin'
password 'admin123'
}
// url to the releases maven repository
url "http://localhost:8081/nexus/content/repositories/releases/"
}
}
}
There is a special command for converting Apache Maven pom.xml files to Gradle build files, if all used Maven plug-ins are known to this task.
In this section the following pom.xml maven configuration will be converted to a Gradle project. Take a look into it.
<project xmlns = "http://maven.apache.org/POM/4.0.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.app</groupId>
<artifactId>example-app</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
You can use the following command on the command line that results in the following Gradle configuration.
C:\> gradle init --type pom
The init task depends on the wrapper task so that a Gradle wrapper is created.
The resulting build.gradle file looks similar to this −
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.example.app'
version = '1.0.0-SNAPSHOT'
description = """"""
sourceCompatibility = 1.5
targetCompatibility = 1.5
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version:'4.11'
}