Fix Gradle repackaging so it is only performed on the desired jars
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 #1204
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user