mirror of
https://github.com/ethauvin/CompileOnlyPlugin.git
synced 2025-04-25 00:37:14 -07:00
Released version 1.0.0 of the plugin.
It adds the java plugin automatically if the java or the groovy plugin is missing. When the idea or eclipse plugin is used, it also adds the new dependencies to their provided scope
This commit is contained in:
parent
3f8e5793d9
commit
0646da0809
6 changed files with 219 additions and 27 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -5,3 +5,7 @@
|
||||||
*.war
|
*.war
|
||||||
*.ear
|
*.ear
|
||||||
.gradle/
|
.gradle/
|
||||||
|
.idea/
|
||||||
|
build/
|
||||||
|
*.iml
|
||||||
|
out/
|
||||||
|
|
106
build.gradle
106
build.gradle
|
@ -1,32 +1,84 @@
|
||||||
/*
|
import org.gradle.api.artifacts.maven.MavenDeployment
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
apply plugin: 'groovy'
|
||||||
// Apply the java plugin to add support for Java
|
apply plugin: 'maven'
|
||||||
apply plugin: 'java'
|
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 {
|
dependencies {
|
||||||
// The production code uses the SLF4J logging API at compile time
|
compile gradleApi()
|
||||||
compile 'org.slf4j:slf4j-api:1.7.5'
|
compile localGroovy()
|
||||||
|
|
||||||
// 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"
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
3
gradle.properties
Normal file
3
gradle.properties
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
group=com.coders-kitchen
|
||||||
|
version=1.0.0
|
||||||
|
rootProject.name=compileonlyplugin
|
|
@ -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<Project> {
|
||||||
|
|
||||||
|
@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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
implementation-class=com.coderskitchen.compileonly.CompileOnlyPlugin
|
|
@ -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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue