diff --git a/.gitignore b/.gitignore index c6eead3..26f6028 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ *.war *.ear .gradle/ +.idea/ +build/ +*.iml +out/ diff --git a/build.gradle b/build.gradle index cb654bc..faf45fc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,32 +1,84 @@ -/* - * This build file was auto generated by running the Gradle 'buildSetup' task - * by 'peter' at '8/12/13 8:56 PM' with Gradle 1.7 - * - * This generated file contains a commented-out sample Java project to get you started. - * For more details take a look at the Java Quickstart chapter in the Gradle - * user guide available at http://gradle.org/docs/1.7/userguide/tutorial_java_projects.html - */ +import org.gradle.api.artifacts.maven.MavenDeployment -/* -// Apply the java plugin to add support for Java -apply plugin: 'java' +apply plugin: 'groovy' +apply plugin: 'maven' +apply plugin: 'signing' -// In this section you declare where to find the dependencies of your project -repositories { - // Use 'maven central' for resolving your dependencies. - // You can declare any Maven/Ivy/file repository here. - mavenCentral() -} -// In this section you declare the dependencies for your production and test code dependencies { - // The production code uses the SLF4J logging API at compile time - compile 'org.slf4j:slf4j-api:1.7.5' - - // Declare the dependency for your favourite test framework you want to use in your tests. - // TestNG is also supported by the Gradle Test task. Just change the - // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add - // 'test.useTestNG()' to your build script. - testCompile "junit:junit:4.11" + compile gradleApi() + compile localGroovy() } -*/ + +task sourcesJar(type: Jar) { + from sourceSets.main.allSource + classifier = 'sources' + archiveName = archiveName.toLowerCase() +} + +jar { + archiveName = archiveName.toLowerCase() +} + +task javadocJar(type: Jar, dependsOn: groovydoc) { + from 'build/docs/groovydoc' + classifier = 'javadoc' + archiveName = archiveName.toLowerCase() +} + +artifacts { + archives jar + archives javadocJar + archives sourcesJar +} + +if (hasProperty('sonatypeUsername')) { + signing { + sign configurations.archives + } + + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: sonatypeUsername, password: sonatypePassword) + } + pom { + project { + name 'CompileOnlyPlugin' + packaging 'jar' + description 'Adds a compile only configuration to the Java plugin of Gradle' + url 'http://coders-kitchen.github.com' + + scm { + url 'scm:git@github:CodersKitchen/CompileOnlyPlugin.git' + connection 'scm:git@github:CodersKitchen/CompileOnlyPlugin.git' + developerConnection 'scm:git@github:CodersKitchen/CompileOnlyPlugin.git' + } + + licenses { + license { + name 'The MIT License (MIT)' + url 'http://opensource.org/licenses/MIT' + distribution 'repo' + } + } + + + developers { + developer { + id 'peterdaum' + name 'Peter Daum' + } + } + } + artifactId = project.name.toLowerCase() + } + } + } + } +} + + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1d23ce5 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +group=com.coders-kitchen +version=1.0.0 +rootProject.name=compileonlyplugin diff --git a/src/main/groovy/com/coderskitchen/compileonly/CompileOnlyPlugin.groovy b/src/main/groovy/com/coderskitchen/compileonly/CompileOnlyPlugin.groovy new file mode 100644 index 0000000..1cfb334 --- /dev/null +++ b/src/main/groovy/com/coderskitchen/compileonly/CompileOnlyPlugin.groovy @@ -0,0 +1,69 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2013 Peter Daum + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.coderskitchen.compileonly + +import org.gradle.api.Plugin +import org.gradle.api.Project + +/** + * This plugin adds a new configuration for compile only dependencies. + * + * It requires the java or groovy plugin applied. If one of these is missing the + * java plugin will be applied automatically. + * + * When the idea or eclipse plugin is present this plugin takes also care of publishing + * this new configuration as a provided dependency path to the IDEs + */ +class CompileOnlyPlugin implements Plugin { + + @Override + void apply(Project t) { + final plugins = t.plugins + if (!plugins.hasPlugin('java')) { + t.logger.quiet 'Java plugin missing, but required. Will be added' + t.apply plugin: 'java' + } + + t.configurations { compileOnly } + def cc = { + compileClasspath += t.configurations.compileOnly + } + t.sourceSets { + main cc + test cc + } + + t.afterEvaluate { + + if (plugins.hasPlugin('idea')) { + t.idea.module.scopes.PROVIDED.plus += t.configurations.compileOnly + } + + if (plugins.hasPlugin('eclipse')) { + t.eclipse.classpath.plusConfigurations += t.configurations.compileOnly + } + } + + + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/gradle-plugins/compileOnly.properties b/src/main/resources/META-INF/gradle-plugins/compileOnly.properties new file mode 100644 index 0000000..6a5ed57 --- /dev/null +++ b/src/main/resources/META-INF/gradle-plugins/compileOnly.properties @@ -0,0 +1 @@ +implementation-class=com.coderskitchen.compileonly.CompileOnlyPlugin diff --git a/src/test/groovy/com/coderskitchen/compileonly/CompileOnlyPluginTest.groovy b/src/test/groovy/com/coderskitchen/compileonly/CompileOnlyPluginTest.groovy new file mode 100644 index 0000000..aec76eb --- /dev/null +++ b/src/test/groovy/com/coderskitchen/compileonly/CompileOnlyPluginTest.groovy @@ -0,0 +1,63 @@ +package com.coderskitchen.compileonly + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.junit.Test + +/** + * Created with IntelliJ IDEA. + * User: peter + * Date: 8/12/13 + * Time: 10:02 PM + * To change this template use File | Settings | File Templates. + */ +class CompileOnlyPluginTest { + @Test + void testWithoutJavaPlugin() { + Project p = ProjectBuilder.builder().build() + p.apply plugin: 'compileOnly' + + p.evaluate() + + assert p.configurations.hasProperty('compileOnly') + + } + + @Test + void testWithJavaPlugin() { + Project p = ProjectBuilder.builder().build() + p.apply plugin: 'java' + p.apply plugin: 'compileOnly' + + p.evaluate() + + assert p.configurations.hasProperty('compileOnly') + + } + + @Test + void testWithIdeaPlugin() { + Project p = ProjectBuilder.builder().build() + p.apply plugin: 'java' + p.apply plugin: 'idea' + p.apply plugin: 'compileOnly' + + p.evaluate() + + assert !p.idea.module.scopes.PROVIDED.plus.findAll{it.name == "compileOnly"}.empty + + } + + @Test + void testWithEclipsePlugin() { + Project p = ProjectBuilder.builder().build() + p.apply plugin: 'java' + p.apply plugin: 'eclipse' + p.apply plugin: 'compileOnly' + + p.evaluate() + + assert !p.eclipse.classpath.plusConfigurations.findAll{it.name == "compileOnly"}.empty + + } +}