Using artifactory in gradle - gradle

I want to use an artifactory in gradle. To be more specific, i want to use 4 customized jars that are not in the maven repository. So i'd like them to be at the artifactory server and will be downloaded when needed.
Do i need to install something other than "Gradle eclipse integration" ?
Can someone give me an example on how to do that in the gradle.build?

First, you need to deploy those jars to Artifactory.
Probably, using the UI will be the easiest way to go.
Next, you need to declare Artifactory as your repository. You can do it by using the standard repositories clause (as #lance-java suggested), or by using Artifactory Gradle plugin. Probably the easiest will be generating the build script snippet from Artifactory itself.
Last will be adding the dependencies to your script. You can navigate to the jars you uploaded in the tree browser, and copy the snippets of dependency declarations from there.
Both steps are documented in the User Guide as well.
I am with JFrog, the company behind Bintray and [artifactory], see my profile for details and links.

repositories {
maven {
url "http://repo.mycompany.com/maven2"
}
}
dependencies {
compile "com.foo.mycompany:dep1:1.0"
compile "com.foo.mycompany:dep2:1.0"
compile "com.foo.mycompany:dep3:1.0"
compile "com.foo.mycompany:dep4:1.0"
}

Related

Make a Gradle project work without an internet connection

Given a Gradle project, that has:
Runtime/Compile-time dependencies.
Source/Javadoc Jars of dependencies.
Gradle plugins.
All of which are retrieved from the internet.
How can I download all of these online dependencies to a local folder, and then use them locally in a Gradle project?
The goal is to end up with a project that doesn't rely on an internet connection at all.
You can do a one-time download of your required dependencies to a local folder, and add a local "maven repo", besides the dependencies, it should also work for sources.
repositories {
maven {
url 'file://C:/LocalRepo'
}
}

How to resolve and deploy dependencies using Gradle with a Maven settings.xml file?

I would like to know if it's possible to resolve and deploy artifacts from/to a Maven repository using Gradle and a Maven settings.xml file. The repository is a secured one, so credentials are required in order to access it. Also, is it possible to specify the location of the settings.xml (I'm asking as we have a few different ones for different teams and we manage these through our CI server)?
A basic example would be really nice. Thanks!
To fetch dependencies form a custom maven repo you can add/configure repositories like
repositories {
maven {
credentials {
username 'user'
password 'password'
}
url "http://repo.mycompany.com/maven2"
}
}
To publish your artefacts you can look into apply plugin: 'maven-publish' plugin depending on which version of Gradle you are using.
And for configuring I think net.linguica.maven-settings is the plugin you can look into.
Additional sources:
net.linguica.maven-settings
gradle repositories
maven publish plugin
You could adapt the code from the maven-settings-decoder to decrypt the passwords in maven settings files for usage in gradle.
It would be nice to turn this into a gradle plugin but that would create a chicken-or-egg problem where the plugin can't be downloaded from the repository because you don't yet have the password.

How to use gradle without maven

Is it possible to use gradle without maven?
I ask this question because I've encounered a case where it isn't possible. For example, I have a project(let it be project A) which results in a jar file after the build. This project is used by another project(project B). When I change smth in project A, project B has to see those changes. In maven we could simply make mvn install on project A, then refresh dependencies on project B and changes hapen to be seen there(in project B)
Gradle has an opportunity to use maven plugin which can do the descibed thing. But in that case we rely on maven(maven repo in particular). I was founding information(seems on stackoverflow also) that gradle filestore, which is located in GRADLE_USER_HOME, is only a cache and can't be used for such purpose.
So, how to achieve that functionality in gradle
Thanks
Gradle downloads dependencies from repositories. These repositories can be Maven repositories, Ivy repositories, local Maven repositories or file repositories. So, to solve your use-case, you would indeed have to publish A to a repository, and to use this repository as the source of the A dependency in B.
See the documentation for more details.

How does Gradle/Ivy read a Nexus repo acting as a Maven mirror?

How does Ivy read a Nexus repo acting as a Maven mirror?
I was thinking about using Gradle as my build system, and Gradle is built from Ant+Ivy (using Groovy). I have a Nexus repository on my local network that acts as a "mirror". In order for me to build my projects, I put a "mirror" entry in my .m2\settings.xml config file. I am able to build my Maven projects just fine but Gradle does not read the .m2 config and so my Gradle projects wont build.
I do not know how to configure Gradle to use the nexus repo as a mirror. Can anyone explain this or give me some hints? I suspect it has something to do with usage of a ivysettings.xml file maybe? This post implies that Gradle DOES in fact read the Maven config but I do not experience this.
I'm using Gradle with a Nexus repo and a Maven proxy and I did not have to modify any of those xml files. I just installed Nexus, created a user with a password through the admin UI, and added this config in my gradle init script (e.g. ${USER_HOME}/.gradle/init.gradle):
allprojects {
repositories {
// Third party dependencies are fetched from MavenCental through a Nexus proxy repository
maven {
credentials {
username 'some_username'
password 'some_password'
}
url 'http://dev.primalogik.com/nexus/content/groups/public/'
}
}
dependencies {
// Example of a compile time dependency
compile group: 'com.google.gwt', name: 'gwt-dev', version: '2.5.1'
...
}
}
The following answer describes how to configure a Maven repository manager in ivy:
Use public maven repository with ivy
I'm uncertain whether this actually helps with a Gradle build (I thought Gradle had stopped using ivy).
Update
Gradle documentation on configuring repositories:
http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:maven_repo

how to build playorm JARs

I am new to playorm and gradle. My goal is to get playorm compiled (especially play 2.1 plugin) and deployed to local nexus repository manager.
What gradle tasks should I invoke to do this?
I tried to run gradlew clean assemble - creates workspace*.jar in output/libs so I assume build part was done. How to get these artefacts renamed and uploaded to my nexus?
https://github.com/deanhiller/playorm
You'll want to read this chapter of the user guide. It looks like the only repository configured for playorm is Maven Central, but the user guide tells you how to configure your own repository and interact with it. After following the guide, if you have a more specific question ask again here.
I created local.gradle and included it in build.gradle to create uploadArchives task using standard gradle upload procedure.
build.gradle was modified in upstream version to include local.gradle if exists.

Resources