Gradle¶
This is an example of how to use the Strongbox artifact repository manager with Gradle.
Pre-requisites¶
- Installed and configured a Strongbox Distribution
- Java Development Kit (JDK) version 1.8.x
- Gradle version 2.11 or higher
Example project¶
The "Hello, Strongbox!" example project can be found [here][hello-strongbox-ant-ivy].
Configuring gradle¶
The gradle.build file¶
This is a build script written in Groovy. Artifact-related properties could be defined and customized in the following way:
- Add
groupproperty to specify logical prefix where other similar projects reside (like thegroupIdin a Mavenpom.xmlfile) - Add
versionto specify artifact's version - Customize the
repositoriessection to add any artifact repositories such as Maven Central (included by default) - Customize the
dependenciessection to add any dependencies to your project; dependency management could be implemented usingextproperties object and applying common settings from single separate gradle file, read more here - Customize
uploadArchivesto specify artifact-to-repository uploading process, matches MavendistributionManagementsection
Read more on gradle scripting here.
The settings.gradle file¶
Use this file to specify project-specific settings of gradle build as well as the artifact's name under the rootProject.name property.
The gradle.properties file¶
This file should be created manually by every developer, or it's perfectly fine to have global settings located in .gradle/gradle.properties. For more details please visit Gradle Build environment page. Here are the properties for this example project:
mavenUser=maven
mavenPassword=password
Credentials¶
Via gradle.properties¶
As illustrated in the section above, you should place your credentials in the gradle.properties in your project's root, or in the ~/.gradle directory (which will have a global impact). Add the following properties:
mavenUser=maven
mavenPassword=password
The down side here is that you would need to have this file on the file system.
Via command-line¶
Specify the following Java args:
-Dcredentials.username=maven -Dcredentials.password=password
The benefit of doing it like this is that you don't need to have the credentials stored in a file on the file system. Most CI servers would allow you to pass in a secured value for credential properties.
How to build from source code¶
When you clone this example project sources, go into that directory and execute gradle clean upload.
This will try to deploy artifacts to the Strongbox Repository.
How to customize target artifact repository during upload¶
Change the repositories.mavenDeployer.repository property and specify the URL and credentials of any repository you
would like to upload to. Make sure you don't have SNAPSHOT in your version if you are uploading to the release
repository.
Example output
>:hello-strongbox-gradle neo$ gradle clean upload
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:javadoc
:javadocJar
:sourcesJar
:uploadArchives
Could not find metadata upload:hello-strongbox-gradle:1.0-SNAPSHOT/maven-metadata.xml in remote (http://localhost:48080/storages/storage0/snapshots/)
Could not find metadata upload:hello-strongbox-gradle/maven-metadata.xml in remote (http://localhost:48080/storages/storage0/snapshots/)
BUILD SUCCESSFUL
Total time: 13.035 secs
You might see a warning stating metadata.xml could not be found in remote. This is normal because this is the first time
you are deploying the artifact and at this point there is no metadata.xml available. It will be available after you
have deployed the artifact for the first time. When you deploy it a second time you will not see the warning since
the metadata.xml is now available at the remote.
Example output
>:hello-strongbox-gradle neo$ gradle clean upload
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:javadoc
:javadocJar
:sourcesJar
:uploadArchives
BUILD SUCCESSFUL
Total time: 2.034 secs
Troubleshooting¶
- If you see error about missing metadata.xml or something similar for the FIRST time when you upload an artifact - don't worry, because this simply said that you are new to this repository entry and there is no existing metadata for your artifact. It will be created.
See Also¶
- Gradle: Tutorial Using Tasks
- Gradle: Artifact Management
- Gradle: Build Environment
- Spring: Building Java Projects with Gradle