Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
Issue #8: Allow for applying the Java plugin after the Nexus plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuschko committed Nov 2, 2014
1 parent b322dcd commit ba04ed7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@
*/
package com.bmuschko.gradle.nexus.singleproject

import com.bmuschko.gradle.nexus.AbstractIntegrationTest
import com.bmuschko.gradle.nexus.ExtraArchivePlugin
import org.gradle.tooling.model.GradleProject
import org.gradle.tooling.model.Task
import spock.lang.Issue

/**
* Nexus plugin archive task integration tests.
*
* @author Benjamin Muschko
*/
class SingleProjectArchiveTaskIntegrationTest extends SingleProjectBuildIntegrationTest {
class SingleProjectArchiveTaskIntegrationTest extends AbstractIntegrationTest {
def "Adds sources and Javadoc JAR tasks by default for Java project"() {
given:
buildFile << """
apply plugin: 'java'
apply plugin: com.bmuschko.gradle.nexus.NexusPlugin
"""

when:
GradleProject project = runTasks(integTestDir, 'tasks')

Expand All @@ -40,6 +48,12 @@ class SingleProjectArchiveTaskIntegrationTest extends SingleProjectBuildIntegrat
}

def "Adds sources and Javadoc JAR tasks by default for Groovy project"() {
given:
buildFile << """
apply plugin: 'java'
apply plugin: com.bmuschko.gradle.nexus.NexusPlugin
"""

when:
GradleProject project = runTasks(integTestDir, 'tasks')

Expand All @@ -56,6 +70,9 @@ class SingleProjectArchiveTaskIntegrationTest extends SingleProjectBuildIntegrat
def "Adds tests JAR task if configured"() {
when:
buildFile << """
apply plugin: 'java'
apply plugin: com.bmuschko.gradle.nexus.NexusPlugin
extraArchive {
tests = true
}
Expand All @@ -77,6 +94,9 @@ extraArchive {
def "Disables additional JAR creation"() {
when:
buildFile << """
apply plugin: 'java'
apply plugin: com.bmuschko.gradle.nexus.NexusPlugin
extraArchive {
sources = false
javadoc = false
Expand All @@ -89,4 +109,23 @@ extraArchive {
!project.tasks.find { task -> task.name == ExtraArchivePlugin.JAVADOC_JAR_TASK_NAME}
!project.tasks.find { task -> task.name == ExtraArchivePlugin.TESTS_JAR_TASK_NAME}
}

@Issue("https://github.com/bmuschko/gradle-nexus-plugin/issues/8")
def "Java plugin can be applied after Nexus plugin"() {
given:
buildFile << """
apply plugin: com.bmuschko.gradle.nexus.NexusPlugin
apply plugin: 'java'
"""

when:
GradleProject project = runTasks(integTestDir, 'tasks')

then:
Task sourcesJarTask = project.tasks.find { task -> task.name == ExtraArchivePlugin.SOURCES_JAR_TASK_NAME }
sourcesJarTask
Task javadocJarTask = project.tasks.find { task -> task.name == ExtraArchivePlugin.JAVADOC_JAR_TASK_NAME }
javadocJarTask
!project.tasks.find { task -> task.name == ExtraArchivePlugin.TESTS_JAR_TASK_NAME }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class ExtraArchivePlugin implements Plugin<Project> {

private void configureTasks(Project project, ExtraArchivePluginExtension extension) {
project.afterEvaluate {
configureSourcesJarTask(project, extension)
configureTestsJarTask(project, extension)
configureJavadocJarTask(project, extension)
project.plugins.withType(JavaPlugin) {
configureSourcesJarTask(project, extension)
configureTestsJarTask(project, extension)
configureJavadocJarTask(project, extension)
}
}
}

Expand Down Expand Up @@ -60,22 +62,12 @@ class ExtraArchivePlugin implements Plugin<Project> {
if(hasGroovyPlugin(project)) {
javaDocJarTask.from project.groovydoc
}
else if(hasJavaPlugin(project)) {
else {
javaDocJarTask.from project.javadoc
}
}
}

/**
* Checks to see if Java plugin got applied to project.
*
* @param project Project
* @return Flag
*/
private boolean hasJavaPlugin(Project project) {
hasPlugin(project, JavaPlugin)
}

/**
* Checks to see if Groovy plugin got applied to project.
*
Expand Down

0 comments on commit ba04ed7

Please sign in to comment.