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:
dummy
locally?SNAPSHOT
version that other projects always pick up the latest copy of?SNAPSHOT
? Something like compile ':dummy:LATEST'
?Gradle's local repository folder is: $USER_HOME/. gradle/caches/modules-2/files-2.1.
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.
Here I've prepared sample project for you, this is the bare minimum when it comes to build.gradle
configuration.
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.
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'
}
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With