Until now, we explained how to build a JAR project with Gradle; let's add a task to deploy an artifact on the repository with the following lines:
uploadArchives { repositories { ext.configuration = configurations.deployerJars mavenDeployer { repository(url: "http://ourserver/nexus/content/repositories/releases") { authentication(userName: "user", password: "boh!") } } } }
This code snippet contains the task and object inherited from the Maven plugin.
In the preceding example, we used uploadArchives
to perform the artifact's upload. The uploadArchives
task requires parameters such as which repository to use for the deploy operation passed within the repositories
object. To perform the artifact's upload, we used mavenDeployer
within the object that contains the url
repository and authentication credential; this object is repository
, which contains authentication
within the specification for username
and password
, valorized with our server authentication credentials. In order to enable mavenDeployer
to create a connection to the server, the configuration
variable contains deployerJars
within the wagon-http
library. Using this task, we can upload an artifact to our Maven server.
In the code snippet, we used the new extra properties' ext
syntax to dynamically add content to objects:
ext.configuration = configurations.deployerJars
The old fashion way to declare configuration is called dynamic properties:
configuration = configurations.deployerJars
This example can upload an artifact with the Maven dependency notation:
<dependency> <groupId>org.gradle.test</groupId> <artifactId>gradle-project</artifactId> <version>1.1</version> </dependency>
If we had to change a pom
property at the moment of deployment, we can use the following syntax:
uploadArchives { repositories { ext.configuration = configurations.deployerJarsmavenDeployer { repository(url: "http://ourserver/nexus/content/repositories/releases") { authentication(userName: "user", password: "boh!") } pom.version = '1.0' pom.artifactId = 'gradle-project-second' } } }
Also, add the following two properties:
pom.version = '1.0' pom.artifactId = 'gradle-project-second'
As a result, we will have this POM content on the published library:
<dependency> <groupId>org.gradle.test</groupId> <artifactId>gradle-project-second</artifactId> <version>1.0</version> </dependency>