Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a structure of a gradle project that uses a version-controlled Maven repository.
/*
* The plugins used for this build.
*/
/*
* Provides the compile, test, jar, etc tasks
*/
apply plugin: 'java'
/*
* Generates the Eclipse project files.
* "gradle eclipse"
*/
apply plugin: 'eclipse'
/*
* Publishes the generated jars to the CollabNet Maven server described on commons.gradle.
* "gradle uploadArchives": uploads snapshots
* "gradle uA -Prelease": uploads releases
*/
apply plugin: 'maven'
/*
* Common properties for the Maven configuration.
*/
apply from: "file://$projectDir/../mavenProperties.gradle"
repositories {
mavenCentral()
mavenRepo url: projectMvn.local.snapshots.scm.url
mavenRepo url: projectMvn.local.releases.scm.url
}
dependencies {
compile module("org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final")
testCompile group: 'junit', name: 'junit', version: '4.+'
}
/*
* The source compatibility
*/
sourceCompatibility = 1.7
/*
* The name of the Jar file. Also used as the name uploaded to the maven repo.
*/
archivesBaseName = "maceio-financial-core"
/*
* Maven plugin and group definition.
*/
group = projectMvn.group
/*
* The jar and maven version of the generated artifact.
*/
version = projectMvn.version
jar {
manifest {
attributes 'Implementation-Title': 'Maceio Financial Core',
'Implementation-Version': version
}
}
/*
* Task from the maven plugin
*/
uploadArchives {
repositories {
mavenDeployer {
repository(url: currentMvnServerUrl)
pom.version = version
pom.artifactId = archivesBaseName
}
}
}
marcello@hawaii:/u1/development/workspaces/maceio/maceio-financial/financial-core$ gradle uploadArchives
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:uploadArchives
Uploading: com/maceio/financial/maceio-financial-core/0.0.1-SNAPSHOT/maceio-financial-core-0.0.1-20120424.102046-2.jar to repository remote at file://localhost/u1/development/workspaces/maceio/maven-repo/snapshots
Transferring 0K from remote
Uploaded 0K
BUILD SUCCESSFUL
Total time: 6.824 secs
marcello@hawaii:/u1/development/workspaces/maceio/maceio-financial/financial-core$ gradle uploadArchives -Prelease
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:uploadArchives
Uploading: com/maceio/financial/maceio-financial-core/0.0.1/maceio-financial-core-0.0.1.jar to repository remote at file://localhost/u1/development/workspaces/maceio/maven-repo/releases
Transferring 0K from remote
Uploaded 0K
marcello@hawaii:/u1/development/workspaces/maceio/maceio-financial/financial-core$ gradle properties
:properties
------------------------------------------------------------
Root project
------------------------------------------------------------
allprojects: [root project 'financial-core']
ant: org.gradle.api.internal.project.DefaultAntBuilder@cd7e6f5
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory@327be569
apiDocTitle: financial-core 0.0.1-SNAPSHOT API
archivesBaseName: maceio-financial-core
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler@64126a63
asDynamicObject: org.gradle.api.internal.ExtensibleDynamicObject@7506bce8
assemble: task ':assemble'
build: task ':build'
buildDependents: task ':buildDependents'
buildDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build
buildFile: /u1/development/workspaces/maceio/maceio-financial/financial-core/build.gradle
buildNeeded: task ':buildNeeded'
buildScriptSource: org.gradle.groovy.scripts.UriScriptSource@1be6fc00
buildTasks: [build]
buildscript: org.gradle.api.internal.initialization.DefaultScriptHandler@59aa724f
check: task ':check'
childProjects: {}
class: class org.gradle.api.internal.project.DefaultProject_Decorated
classes: task ':classes'
clean: task ':clean'
cleanEclipse: task ':cleanEclipse'
cleanEclipseClasspath: task ':cleanEclipseClasspath'
cleanEclipseJdt: task ':cleanEclipseJdt'
cleanEclipseProject: task ':cleanEclipseProject'
compileJava: task ':compileJava'
compileTestJava: task ':compileTestJava'
conf2ScopeMappings: org.gradle.api.publication.maven.internal.DefaultConf2ScopeMappingContainer@4208e299
configurations: [configuration ':archives', configuration ':compile', configuration ':default', configuration ':runtime', configuration ':testCompile', configuration ':testRuntime']
convention: org.gradle.api.internal.plugins.DefaultConvention@4536ce86
currentMvnServerUrl: file://localhost/u1/development/workspaces/maceio/maven-repo/snapshots
defaultArtifacts: org.gradle.api.internal.plugins.DefaultArtifactPublicationSet_Decorated@1130e2ea
defaultTasks: []
dependencies: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler@20817977
dependencyCacheDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/dependency-cache
dependencyCacheDirName: dependency-cache
dependsOnProjects: []
depth: 0
description: null
distsDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/distributions
distsDirName: distributions
docsDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/docs
docsDirName: docs
eclipse: org.gradle.plugins.ide.eclipse.model.EclipseModel_Decorated@144d844d
eclipseClasspath: task ':eclipseClasspath'
eclipseJdt: task ':eclipseJdt'
eclipseProject: task ':eclipseProject'
ext: org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension@6d28e5a4
extensions: org.gradle.api.internal.plugins.DefaultConvention@4536ce86
fileResolver: org.gradle.api.internal.file.BaseDirFileResolver@17fca9f9
gradle: build 'financial-core'
group: com.maceio.financial
implicitTasks: [task ':dependencies', task ':help', task ':projects', task ':properties', task ':tasks']
inheritedScope: org.gradle.api.internal.ExtensibleDynamicObject$InheritedDynamicObject@4cfb26bc
install: task ':install'
jar: task ':jar'
javadoc: task ':javadoc'
libsDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/libs
libsDirName: libs
logger: org.gradle.api.logging.Logging$LoggerImpl@7cac281f
logging: org.gradle.logging.internal.DefaultLoggingManager@a7e4b2b
manifest: org.gradle.api.java.archives.internal.DefaultManifest@6978f96e
mavenLocalRepo: file://localhost/u1/development/workspaces/maceio/maven-repo
mavenNexusServer: https://maven.nexus.local:8081/nexus
mavenPomDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/poms
mavenReposServer: https://bitbucket.org/marcellodesales/maceio/raw/master
metaClass: org.codehaus.groovy.runtime.HandleMetaClass@53fdadb[groovy.lang.MetaClassImpl@53fdadb[class org.gradle.api.internal.project.DefaultProject_Decorated]]
metaInf: []
module: org.gradle.api.internal.artifacts.DefaultModule@2339628e
name: financial-core
parent: null
parentIdentifier: null
path: :
plugins: [org.gradle.api.plugins.BasePlugin@535c3667, org.gradle.api.plugins.ReportingBasePlugin@7b2896bb, org.gradle.api.plugins.JavaBasePlugin@426c4c9d, org.gradle.api.plugins.JavaPlugin@9530a8a, org.gradle.plugins.ide.eclipse.EclipsePlugin@7c66eb65, org.gradle.api.plugins.MavenPlugin@64fbccad]
processResources: task ':processResources'
processTestResources: task ':processTestResources'
project: root project 'financial-core'
projectDir: /u1/development/workspaces/maceio/maceio-financial/financial-core
projectEvaluationBroadcaster: ProjectEvaluationListener broadcast
projectEvaluator: org.gradle.configuration.LifecycleProjectEvaluator@c756ab3
projectMvn: {remote={host=https://bitbucket.org/marcellodesales/maceio/raw/master, releases={scm={url=https://bitbucket.org/marcellodesales/maceio/raw/master/releases}, nexus={url=https://maven.nexus.local:8081/nexus/content/repositories/releases, repoId=project-release, username=admin, password=welcome}}, snapshots={scm={url=https://bitbucket.org/marcellodesales/maceio/raw/master/snapshots}, nexus={url=https://maven.nexus.local:8081/nexus/content/repositories/snapshots, repoId=project-release, username=admin, password=welcome}}}, local={host=file://localhost/u1/development/workspaces/maceio/maven-repo, releases={scm={url=file://localhost/u1/development/workspaces/maceio/maven-repo/releases}}, snapshots={scm={url=file://localhost/u1/development/workspaces/maceio/maven-repo/snapshots}}}, group=com.maceio.financial, version=0.0.1-SNAPSHOT}
projectRegistry: org.gradle.api.internal.project.DefaultProjectRegistry@70b01428
properties: {...}
rebuildTasks: [clean, build]
reporting: org.gradle.api.reporting.ReportingExtension_Decorated@37fb87e4
reportsDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/reports
reportsDirName: reports
repositories: [org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated@6296a672, org.gradle.api.internal.artifacts.repositories.FixedResolverArtifactRepository@1089b8ef, org.gradle.api.internal.artifacts.repositories.FixedResolverArtifactRepository@41cc5b64]
resources: org.gradle.api.internal.resources.DefaultResourceHandler@4f8423fb
rootDir: /u1/development/workspaces/maceio/maceio-financial/financial-core
rootProject: root project 'financial-core'
runtimeClasspath: file collection
runtimeRepoType: snapshots
services: ProjectInternalServiceRegistry
sourceCompatibility: 1.7
sourceSets: [source set main, source set test]
standardOutputCapture: org.gradle.logging.internal.DefaultLoggingManager@a7e4b2b
state: project state 'EXECUTED'
status: integration
subprojects: []
targetCompatibility: 1.7
tasks: [task ':assemble', task ':build', task ':buildDependents', task ':buildNeeded', task ':check', task ':classes', task ':clean', task ':cleanEclipse', task ':cleanEclipseClasspath', task ':cleanEclipseJdt', task ':cleanEclipseProject', task ':compileJava', task ':compileTestJava', task ':eclipse', task ':eclipseClasspath', task ':eclipseJdt', task ':eclipseProject', task ':install', task ':jar', task ':javadoc', task ':processResources', task ':processTestResources', task ':test', task ':testClasses', task ':uploadArchives']
test: task ':test'
testClasses: task ':testClasses'
testReportDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/reports/tests
testReportDirName: tests
testResultsDir: /u1/development/workspaces/maceio/maceio-financial/financial-core/build/test-results
testResultsDirName: test-results
uploadArchives: task ':uploadArchives'
version: 0.0.1-SNAPSHOT
versionSuffix: -SNAPSHOT
BUILD SUCCESSFUL
Total time: 16.042 secs
/*
* Copies the generated jar to thirdparty local cache repository WITHOUT Maven repository Metadata.
* Any previous version will be overwritten. Also, the new version must be committed to Subversion. The jar name will
* be influenced by the use of the execution property "-Prelease", which dictates the removal of the suffix "SNAPSHOT"
* in the jar name.
*
* gradle instalThirdparty | gradle iT | gradle iT -Prelease
*/
task installThirdparty(dependsOn: jar, description: "Copies the generated jar ${archivesBaseName}-${version}.jar " +
"in the directory 'thirdparty/'.") << {
// jar properties http://www.gradle.org/current/docs/dsl/org.gradle.api.tasks.bundling.Jar.html
def destinationFile = new File("$projectDir/../../../thirdparty/saturn/${jar.archiveName}").canonicalPath
println "Copying the $jar.archivePath to $destinationFile"
ant.copy(file: jar.archivePath, tofile: destinationFile)
}
/*
* Defines the version tag and the Maven repository to publish if the command-line arg "-Prelease" is defined.
*/
project.ext.set("versionSuffix", hasProperty('release') ? "" : "-SNAPSHOT")
def runtimeRepoType = hasProperty('release') ? "releases" : "snapshots"
project.ext.set("runtimeRepoType", runtimeRepoType)
def mavenReposServer = "https://bitbucket.org/marcellodesales/maceio/raw/master"
project.ext.set("mavenReposServer", mavenReposServer)
def mavenNexusServer = "https://maven.nexus.local:8081/nexus"
project.ext.set("mavenNexusServer", mavenNexusServer)
def localRepoFilePath = new File(projectDir, "../../maven-repo/").canonicalPath
project.ext.set("mavenLocalRepo", "file://localhost" + localRepoFilePath)
/*
* The project Maven server information. Defaults to "snapshot". Use "-Prelease" to publish to the "release" repo.
*/
def projectMaven = [
remote: [
host: mavenReposServer,
releases: [scm: [url: "$mavenReposServer/releases"],
nexus: [url: "$mavenNexusServer/content/repositories/releases",
repoId: "project-release", username: "admin", password: "welcome"]
],
snapshots: [scm: [url: "$mavenReposServer/snapshots"],
nexus: [url: "$mavenNexusServer/content/repositories/snapshots",
repoId: "project-release", username: "admin", password: "welcome"]
]
],
local: [
host: mavenLocalRepo,
releases: [scm: [url: "$mavenLocalRepo/releases"]],
snapshots: [scm: [url: "$mavenLocalRepo/snapshots"]]
],
group: "com.maceio.financial",
version: "0.0.1" + project.versionSuffix
]
/*
* Setting the 'mvn' properties above.
*/
projectMaven.each{ cnProp ->
if (cnProp.equals("group") || cnProp.equals("version")) {
project.ext.set(cnProp.key, cnProp.value)
}
}
project.ext.set("currentMvnServerUrl", hasProperty('release') ? projectMaven.local.releases.scm.url : projectMaven.local.snapshots.scm.url)
project.ext.set("projectMvn", projectMaven)
marcello@hawaii:/u1/development/workspaces/maceio/maceio-financial/financial-core$ tree ../../maven-repo/
../../maven-repo/
├── releases
│   └── com
│   └── maceio
│   └── financial
│   └── maceio-financial-core
│   ├── 0.0.1
│   │   ├── maceio-financial-core-0.0.1.jar
│   │   ├── maceio-financial-core-0.0.1.jar.md5
│   │   ├── maceio-financial-core-0.0.1.jar.sha1
│   │   ├── maceio-financial-core-0.0.1.pom
│   │   ├── maceio-financial-core-0.0.1.pom.md5
│   │   └── maceio-financial-core-0.0.1.pom.sha1
│   ├── maven-metadata.xml
│   ├── maven-metadata.xml.md5
│   └── maven-metadata.xml.sha1
└── snapshots
└── com
└── maceio
└── financial
└── maceio-financial-core
├── 0.0.1-SNAPSHOT
│   ├── maceio-financial-core-0.0.1-20120424.093920-1.jar
│   ├── maceio-financial-core-0.0.1-20120424.093920-1.jar.md5
│   ├── maceio-financial-core-0.0.1-20120424.093920-1.jar.sha1
│   ├── maceio-financial-core-0.0.1-20120424.093920-1.pom
│   ├── maceio-financial-core-0.0.1-20120424.093920-1.pom.md5
│   ├── maceio-financial-core-0.0.1-20120424.093920-1.pom.sha1
│   ├── maven-metadata.xml
│   ├── maven-metadata.xml.md5
│   └── maven-metadata.xml.sha1
├── maven-metadata.xml
├── maven-metadata.xml.md5
└── maven-metadata.xml.sha1
/*
* If the version name ends with "SNAPSHOT" (capital letters), Gradle will automatically upload the artifact to
* the repository "snapshotRepository". Otherwise, it will be uploaded to the regular releases repository.
*/
uploadArchives {
description = "Uploads the generated jar ${archivesBaseName}-${version}.jar to ${projectMvn.remote[runtimeRepoType].nexus.url}"
repositories.mavenDeployer {
repository(url: "${projectMvn.remote.releases.nexus.url}") {
authentication(userName: "${projectMvn.remote.releases.nexus.username}", password: "${projectMvn.remote.releases.nexus.password}")
}
snapshotRepository(url: "${projectMvn.remote.snapshots.nexus.url}") {
authentication(userName: "${projectMvn.remote.snapshots.nexus.username}", password: "${projectMvn.remote.snapshots.nexus.password}")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.