Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing Gradle snapshots locally

Here is my dummy project's build.gradle file:

apply plugin: 'groovy'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.3'
    compile 'org.slf4j:jcl-over-slf4j:1.7.7'

    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-all:1.10.8'
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

When I run gradle clean build -Pversion=1.2.3, this packages up all my code and creates a build/libs/dummy-1.2.3.jar for me.

I would like to know the absolute bare minimum amount of Gradle code necessary so that I could publish my "dummy" JARs to my local Maven cache (mavenLocal()). Additionally, how does this work with versioning? I could always specify a concrete version for the dummy JAR, but when I'm publishing locally, it makes more sense (to me, at least) to publish SNAPSHOT versions. I could just run gradle clean build -Pversion=0.1.SNAPSHOT, but then my concern is whether or not other local projects would pick up the latest SNAPSHOT versions.

So again:

  1. What's the bare minimum code to publish dummy locally?
  2. Any way, when publishing locally, to specify a SNAPSHOT version that other projects always pick up the latest copy of?
  3. What would other local projects need to use to pick up this SNAPSHOT? Something like compile ':dummy:LATEST'?
like image 522
DirtyMikeAndTheBoys Avatar asked Jan 03 '15 07:01

DirtyMikeAndTheBoys


People also ask

Where is the gradle local repository?

Gradle's local repository folder is: $USER_HOME/. gradle/caches/modules-2/files-2.1.

What is mavenLocal in gradle?

Gradle is able to resolve artifacts stored in the local Maven repository (usually ~/. m2/repository ) via mavenLocal(). According to the documentation, mavenLocal() is resolved like this: Gradle uses the same logic as Maven to identify the location of your local Maven cache.


2 Answers

Here I've prepared sample project for you, this is the bare minimum when it comes to build.gradle configuration.

  1. You need to add apply plugin: 'maven' and set group = 'somegroup'. maven plugin gives install task and group is required to install artifact in maven repository.

    Then run gradle clean install. If no version passed, it will evaluate to unspecified, if no artifactId configured it will evaluate to project.name. Here You can find how to configure other maven properties.

    Installing snapshot for local development is definitely a good idea.

  2. If You'd like other project to always pick the latest version of SNAPSHOT You need to add the following piece of code to build.gradle scripts. It guarantees resolving to the latest version.

    configurations.all {
       resolutionStrategy {
         cacheChangingModulesFor 0, 'seconds'
       }
    }
    
  3. First of all You need to add snapshot repo to repositories block (just a sample) - with local maven repo, this step is not needed:

    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots'
    }
    

    Dependency should be specified as:

    group:artifact:0.+
    

Feel free to ask in case of any questions.

like image 102
Opal Avatar answered Oct 23 '22 14:10

Opal


1) You just need to do a

gradle install

2) Specify whatever version you like - a SNAPSHOT version makes sense for active development. Once you think your library is less likely to change you should definitely go for a non-snapshot version.

3) You have to specify a dependency to the version you have in your local repo, just as for 3rd party libraries.

like image 3
sorencito Avatar answered Oct 23 '22 16:10

sorencito