Fix reflective access to archiveBaseName property

Previously, reflective access to the archiveBaseName property
incorrectly treated the property as a String. It should have been
treated as a Property<String>. This caused an exception to be thrown
and the deprecated baseName property to be used as a fallback.

This commit corrects the reflective access to the archiveBaseName
property. It also updates the tests to fail if a build outputs a
deprecation warning. Tests that use Gradle's Maven plugin have been
updated to expect deprecation warnings when run with Gradle 6.0 where
the plugin is deprecated. Tests that configure an archive's base name
have been updated to use archiveBaseName when running with Gradle 6.0
and later.

Closes gh-18663
This commit is contained in:
Andy Wilkinson
2019-11-27 12:45:23 +00:00
parent a58ae98f9d
commit 76f03a8cad
8 changed files with 54 additions and 18 deletions

View File

@@ -24,6 +24,7 @@ import org.gradle.api.Project;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.jvm.tasks.Jar;
@@ -128,11 +129,12 @@ public class SpringBootExtension {
return (Jar) this.project.getTasks().findByName("bootJar");
}
@SuppressWarnings("unchecked")
private static String getArchiveBaseName(AbstractArchiveTask task) {
try {
Method method = findMethod(task.getClass(), "getArchiveBaseName");
if (method != null) {
return (String) method.invoke(task);
return ((Property<String>) method.invoke(task)).get();
}
}
catch (Exception ex) {

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.regex.Pattern;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.springframework.boot.loader.tools.FileUtils;
@@ -57,11 +58,12 @@ public class LaunchScriptConfiguration implements Serializable {
putIfMissing(this.properties, "initInfoDescription", augmentLineBreaks(project.getDescription()), baseName);
}
@SuppressWarnings("unchecked")
private static String getArchiveBaseName(AbstractArchiveTask task) {
try {
Method method = findMethod(task.getClass(), "getArchiveBaseName");
if (method != null) {
return (String) method.invoke(task);
return ((Property<String>) method.invoke(task)).get();
}
}
catch (Exception ex) {