Skip to content

Instantly share code, notes, and snippets.

@quidryan
Created March 20, 2013 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quidryan/5202284 to your computer and use it in GitHub Desktop.
Save quidryan/5202284 to your computer and use it in GitHub Desktop.
How we boostrap the Netflix OSS project to publish internally.
/**
* Establish simple Gradle practices which let an OSS gradle project play nice in the Netflix infrastructure
*
* 1. Establish artifactory repositories as sole repositories
* 2. Add in artfactory plugin
*/
import org.apache.ivy.plugins.resolver.FileSystemResolver;
import org.apache.ivy.plugins.resolver.URLResolver;
// Jenkins workspace
def workspace = System.getenv()['WORKSPACE']
if (workspace == null || workspace.trim().isEmpty()) {
workspace = System.getenv()['HOME']
}
// Establish "workspace friendly" ivy home, used for its cache.
// We have to override Ivy's settings before we get too far into the process.
// In OSS project, WORKSPACE is not likely the P4 workspace, but is the one for Jenkins, meaning that local builds
// won't have WORKSPACE.
def ivyHomeKey = 'ivy.default.ivy.user.dir'
if (System.getProperty(ivyHomeKey) == null) {
// TODO Ensure workspace is a proper directory
System.setProperty(ivyHomeKey, workspace + '/.ivy2')
}
def artifactsBase = 'http://artifacts.netflix.com/'
def ivyIvyPattern = '[organisation]/[module]/[revision]/[module]-[revision]-ivy.[ext]'
def ivyArtifactPattern = '[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'
// Clean up all repositories to only include Netflix repos
// When calling directly via -I use initscript
// When calling via apply from, use buildscript
buildscript {
repositories.clear()
repositories {
maven { // Pulls from repo.jfrog.com and repo1, so it has a maven layout.
name 'build-gradle'
url 'http://artifacts.netflix.com/build-gradle' // artifactsBase isn't available, because buildscript is executed by itself
}
}
}
allprojects {
afterEvaluate { project ->
def localPublishDir = new File("${workspace}/ivy2-local").absolutePath
// Ensure that only our "approved" repository is available while building
repositories.clear()
repositories {
add(new FileSystemResolver()) {
name = 'local'
addIvyPattern "${localPublishDir}/${ivyIvyPattern}"
addArtifactPattern "${localPublishDir}/${ivyArtifactPattern}"
checkmodified = true
}
// Public artifacts used by Netflix projects
add(new URLResolver()) {
name = ['release','candidate','snapshot'].contains(project.status) ? "nfrepo-${project.status}s":'ext-releases-local'
def artifactsUrl = artifactsBase + name
addIvyPattern "${artifactsUrl}/${ivyIvyPattern}"
addArtifactPattern "${artifactsUrl}/${ivyArtifactPattern}"
m2compatible = true
}
}
try {
def archiveConf = project.configurations.find { it.name == 'archives' }
if(archiveConf) {
project.tasks.add(name: 'uploadLocal', type:Upload) {
configuration = archiveConf
repositories {
add(new FileSystemResolver()) {
name = 'local'
// Requires workspace variables
addIvyPattern "${localPublishDir}/${ivyIvyPattern}"
addArtifactPattern "${localPublishDir}/${ivyArtifactPattern}"
}
}
description = "Upload artifacts to \$WORKSPACE/ivy2-local"
group = BasePlugin.UPLOAD_GROUP
uploadDescriptor = true
descriptorDestination = new File(project.getBuildDir(), "ivy.xml")
}
}
} catch(UnknownConfigurationException uce) {
}
}
}
buildscript {
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.17')
}
}
allprojects {
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin.class
}
rootProject {
// Internal Netflix Repository, to be published to
artifactory {
publish {
contextUrl = artifactsBase
// Put everything in defaults, so that it will be evaluated after the project. The project might set things like status,
// which we need for the repository. Defaults will delegate to artifactory.publish.
defaults {
repository {
repoKey = "libs-${it.project.status}s-local" // The Artifactory repository key to publish to. Not sure if we're enforcing status correctly.
ivy {
ivyLayout = ivyIvyPattern
artifactLayout = ivyArtifactPattern
mavenCompatible = true // Convert dots in [organization] to directory separators
}
}
// build-info will ALWAYS use archives to build ivy, and will hence depends on uploadArchives no matterwhat
// Ideally, we're switch this to a custom config which extends from runtime
// Has to be a string, since we want to refer to the archives config for each child project
publishConfigs('archives')
properties = ['build.status': project.status.toString(), 'build.version': project.version]
publishPom = false // Publish generated POM files to Artifactory (true by default)
publishIvy = true // Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment