Browse Source
The logic that determined whether or not the repackaging action should be applied to a particular jar task was broken and caused problems when a custom RepackageTask was used in a project's build. This commit updates the logic so that repackaging will be applied: - To the default jar task if RepackageTask.withJarTask is null - To a jar task if it is equal to RepackageTask.withJarTask - To a jar task if its name is equal to RepackageTask.withJarTask Repackaging is not applied if: - RepackageTask.enabled is false Numerous integration tests have been added to verify the repackaging behaviour. Fixes #1204pull/1209/head
3 changed files with 179 additions and 16 deletions
@ -0,0 +1,114 @@
@@ -0,0 +1,114 @@
|
||||
/* |
||||
* Copyright 2012-2014 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.gradle; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import org.gradle.tooling.ProjectConnection; |
||||
import org.junit.BeforeClass; |
||||
import org.junit.Test; |
||||
import org.springframework.boot.dependency.tools.ManagedDependencies; |
||||
|
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
public class RepackagingTests { |
||||
|
||||
private static final String BOOT_VERSION = ManagedDependencies.get() |
||||
.find("spring-boot").getVersion(); |
||||
|
||||
private static ProjectConnection project; |
||||
|
||||
@BeforeClass |
||||
public static void createProject() throws IOException { |
||||
project = new ProjectCreator().createProject("repackage"); |
||||
} |
||||
|
||||
@Test |
||||
public void repackagingEnabled() { |
||||
project.newBuild().forTasks("clean", "build") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); |
||||
File buildLibs = new File("target/repackage/build/libs"); |
||||
assertTrue(new File(buildLibs, "repackage.jar").exists()); |
||||
assertTrue(new File(buildLibs, "repackage.jar.original").exists()); |
||||
assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void repackagingDisabled() { |
||||
project.newBuild().forTasks("clean", "build") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false") |
||||
.run(); |
||||
File buildLibs = new File("target/repackage/build/libs"); |
||||
assertTrue(new File(buildLibs, "repackage.jar").exists()); |
||||
assertFalse(new File(buildLibs, "repackage.jar.original").exists()); |
||||
assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void repackagingDisabledWithCustomRepackagedJar() { |
||||
project.newBuild().forTasks("clean", "build", "customRepackagedJar") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false") |
||||
.run(); |
||||
File buildLibs = new File("target/repackage/build/libs"); |
||||
assertTrue(new File(buildLibs, "repackage.jar").exists()); |
||||
assertFalse(new File(buildLibs, "repackage.jar.original").exists()); |
||||
assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void repackagingDisabledWithCustomRepackagedJarUsingStringJarTaskReference() { |
||||
project.newBuild() |
||||
.forTasks("clean", "build", "customRepackagedJarWithStringReference") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false") |
||||
.run(); |
||||
File buildLibs = new File("target/repackage/build/libs"); |
||||
assertTrue(new File(buildLibs, "repackage.jar").exists()); |
||||
assertFalse(new File(buildLibs, "repackage.jar.original").exists()); |
||||
assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void repackagingEnabledWithCustomRepackagedJar() { |
||||
project.newBuild().forTasks("clean", "build", "customRepackagedJar") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); |
||||
File buildLibs = new File("target/repackage/build/libs"); |
||||
assertTrue(new File(buildLibs, "repackage.jar").exists()); |
||||
assertTrue(new File(buildLibs, "repackage.jar.original").exists()); |
||||
assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void repackagingEnableWithCustomRepackagedJarUsingStringJarTaskReference() { |
||||
project.newBuild() |
||||
.forTasks("clean", "build", "customRepackagedJarWithStringReference") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); |
||||
File buildLibs = new File("target/repackage/build/libs"); |
||||
assertTrue(new File(buildLibs, "repackage.jar").exists()); |
||||
assertTrue(new File(buildLibs, "repackage.jar.original").exists()); |
||||
assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar").exists()); |
||||
assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
||||
} |
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
buildscript { |
||||
repositories { |
||||
mavenLocal() |
||||
} |
||||
dependencies { |
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}" |
||||
} |
||||
} |
||||
|
||||
repositories { |
||||
mavenLocal() |
||||
mavenCentral() |
||||
} |
||||
|
||||
apply plugin: 'spring-boot' |
||||
apply plugin: 'java' |
||||
|
||||
dependencies { |
||||
compile 'org.springframework.boot:spring-boot-starter-freemarker' |
||||
compile "org.springframework.boot:spring-boot-starter-web" |
||||
} |
||||
|
||||
springBoot { |
||||
mainClass = 'foo.bar.Baz' |
||||
} |
||||
|
||||
bootRepackage.enabled = Boolean.valueOf(project.repackage) |
||||
|
||||
task customJar(type: Jar) { |
||||
archiveName = 'custom.jar' |
||||
from sourceSets.main.output |
||||
} |
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) { |
||||
classifier = 'sources' |
||||
from sourceSets.main.allSource |
||||
} |
||||
|
||||
artifacts { |
||||
archives sourcesJar |
||||
} |
||||
|
||||
task customRepackagedJar(type: BootRepackage, dependsOn: customJar) { |
||||
withJarTask = customJar |
||||
} |
||||
|
||||
task customRepackagedJarWithStringReference(type: BootRepackage, dependsOn: customJar) { |
||||
withJarTask = 'customJar' |
||||
} |
||||
Loading…
Reference in new issue