diff --git a/src/integTest/groovy/com/bmuschko/gradle/nexus/singleproject/SingleProjectArchiveTaskIntegrationTest.groovy b/src/integTest/groovy/com/bmuschko/gradle/nexus/singleproject/SingleProjectArchiveTaskIntegrationTest.groovy index a3982f1..8bb8968 100644 --- a/src/integTest/groovy/com/bmuschko/gradle/nexus/singleproject/SingleProjectArchiveTaskIntegrationTest.groovy +++ b/src/integTest/groovy/com/bmuschko/gradle/nexus/singleproject/SingleProjectArchiveTaskIntegrationTest.groovy @@ -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') @@ -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') @@ -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 } @@ -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 @@ -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 } + } } diff --git a/src/main/groovy/com/bmuschko/gradle/nexus/ExtraArchivePlugin.groovy b/src/main/groovy/com/bmuschko/gradle/nexus/ExtraArchivePlugin.groovy index 7a641f0..4482baa 100644 --- a/src/main/groovy/com/bmuschko/gradle/nexus/ExtraArchivePlugin.groovy +++ b/src/main/groovy/com/bmuschko/gradle/nexus/ExtraArchivePlugin.groovy @@ -21,9 +21,11 @@ class ExtraArchivePlugin implements Plugin { 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) + } } } @@ -60,22 +62,12 @@ class ExtraArchivePlugin implements Plugin { 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. *