Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Began work on GenerateMavenBom task
Browse files Browse the repository at this point in the history
* Added it to the new :buildSrc project, along with a preliminary test.
* Updated .gitignore so that source code in the "edu.ucar.build" package isn't ignored
  • Loading branch information
cwardgar committed Jan 18, 2016
1 parent c9d514b commit d7e01cc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ _compareTemp
bin/
*~

# Ignore gradle stuff
# Ignore the Gradle cache directory.
.gradle/
# Ignore the output that Gradle generates in the "build/" directories...
build/
# ...but not the source code in the "edu.ucar.build" package.
!**/src/**/edu/ucar/build/

# Ignore default content directory for mock servlets
tds/src/content/
Expand Down
34 changes: 34 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apply plugin: 'groovy'

apply from: "../gradle/dependencies.gradle"

dependencies {
compile gradleApi() // We're developing a custom task, so we need the Gradle API.

testCompile (libraries["spock-core"]) {
// The Gradle API drags in the bundled version of Groovy that Gradle ships with (localGroovy()) –
// see https://discuss.gradle.org/t/unable-to-force-gradle-to-use-groovy-2-0-0-for-the-project/7021.
// Spock drags in another Groovy as a transitive dependency.
//
// So, there are multiple candidate versions of the Groovy dependency. Ordinarily, this is no problem for
// Gradle; it bas version-conflict-resolution machinery to deal with it. However, localGroovy() is a special
// kind of dependency that doesn't participate in that resolution (again, see above URL).
//
// Once added to a configuration, localGroovy() will remain part of it no matter what. Furthermore, since
// localGroovy() is "special", Gradle will not consider a second, "normal" Groovy dependency to be in conflict
// with it. This can result in two different versions of Groovy in the same configuration, and ultimately
// errors like: "groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded
// in version 2.4.4 and you are trying to load version 2.4.1".
//
// Our solution is to explicitly exclude any other Groovy dependencies whenever localGroovy() is already part
// of the configuration.
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
}

task foo << {
println rootProject?.name
println project?.name
println project?.parent?.name
println "$rootDir"
}
18 changes: 18 additions & 0 deletions buildSrc/src/main/groovy/edu/ucar/build/GenerateMavenBom.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.ucar.build

import org.gradle.api.publish.maven.tasks.GenerateMavenPom
import org.gradle.api.tasks.TaskAction

/**
*
*
* @author cwardgar
* @since 2016-01-16
*/
class GenerateMavenBom extends GenerateMavenPom {
@TaskAction
def generateBom() {
println "YAY!"
println "Project: $project"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.ucar.build

import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification

/**
*
*
* @author cwardgar
* @since 2016-01-16
*/
class GenerateMavenBomTest extends Specification {
def "DoIt"() {
setup:
ProjectBuilder builder = ProjectBuilder.builder().withName("GenerateMavenBomTest")
Project project = builder.build()

Task task = project.tasks.create(name: 'generateBom', type: GenerateMavenBom) {
}

when:
task.generateBom()

then:
true
}
}

0 comments on commit d7e01cc

Please sign in to comment.