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
by default, maven-publish plugin is provided by gradle. it is 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/" } } }
converting from maven to gradle
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.
<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' }