diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy index ef83ff3b5..6b3c9515c 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy @@ -9,7 +9,6 @@ import org.gradle.api.distribution.Distribution import org.gradle.api.distribution.DistributionContainer import org.gradle.api.file.CopySpec import org.gradle.api.plugins.ApplicationPlugin -import org.gradle.api.plugins.ApplicationPluginConvention import org.gradle.api.plugins.JavaApplication import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.provider.Provider @@ -26,12 +25,12 @@ class ShadowApplicationPlugin implements Plugin { public static final String SHADOW_INSTALL_TASK_NAME = 'installShadowDist' private Project project - private ApplicationPluginConvention pluginConvention + private JavaApplication javaApplication @Override void apply(Project project) { this.project = project - this.pluginConvention = (ApplicationPluginConvention) project.convention.plugins.application + this.javaApplication = project.extensions.getByType(JavaApplication) DistributionContainer distributions = project.extensions.getByName("distributions") Distribution distribution = distributions.create("shadow") @@ -46,7 +45,7 @@ class ShadowApplicationPlugin implements Plugin { } protected void configureJarMainClass(Project project) { - def classNameProvider = project.provider { getMainClassName() } + def classNameProvider = javaApplication.mainClass jar.configure { jar -> jar.inputs.property('mainClassName', classNameProvider) jar.doFirst { @@ -55,18 +54,7 @@ class ShadowApplicationPlugin implements Plugin { } } - private Object getMainClassName() { - def mainClassName = project.convention.plugins.application.mainClassName - if (Objects.nonNull(mainClassName)) { - return mainClassName - } - - return project.extensions.getByType(JavaApplication.class).mainClass.get() - } - protected void addRunTask(Project project) { - ApplicationPluginConvention pluginConvention = ( - ApplicationPluginConvention) project.convention.plugins.application project.tasks.register(SHADOW_RUN_TASK_NAME, JavaJarExec) { run -> def install = project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync) @@ -74,7 +62,7 @@ class ShadowApplicationPlugin implements Plugin { run.mainClass.set('-jar') run.description = 'Runs this project as a JVM application using the shadow jar' run.group = ApplicationPlugin.APPLICATION_GROUP - run.conventionMapping.jvmArgs = { pluginConvention.applicationDefaultJvmArgs } + run.conventionMapping.jvmArgs = { javaApplication.applicationDefaultJvmArgs } run.conventionMapping.jarFile = { project.file("${install.get().destinationDir.path}/lib/${jar.get().archivePath.name}") } @@ -90,32 +78,26 @@ class ShadowApplicationPlugin implements Plugin { } protected void addCreateScriptsTask(Project project) { - ApplicationPluginConvention pluginConvention = - (ApplicationPluginConvention) project.convention.plugins.application - project.tasks.register(SHADOW_SCRIPTS_TASK_NAME, CreateStartScripts) { startScripts -> startScripts.unixStartScriptGenerator.template = project.resources.text.fromString(this.class.getResource("internal/unixStartScript.txt").text) startScripts.windowsStartScriptGenerator.template = project.resources.text.fromString(this.class.getResource("internal/windowsStartScript.txt").text) startScripts.description = 'Creates OS specific scripts to run the project as a JVM application using the shadow jar' startScripts.group = ApplicationPlugin.APPLICATION_GROUP startScripts.classpath = project.files(jar) - startScripts.conventionMapping.mainClassName = { pluginConvention.mainClassName } - startScripts.conventionMapping.applicationName = { pluginConvention.applicationName } + startScripts.conventionMapping.mainClassName = { javaApplication.mainClass.get() } + startScripts.conventionMapping.applicationName = { javaApplication.applicationName } startScripts.conventionMapping.outputDir = { new File(project.buildDir, 'scriptsShadow') } - startScripts.conventionMapping.defaultJvmOpts = { pluginConvention.applicationDefaultJvmArgs } + startScripts.conventionMapping.defaultJvmOpts = { javaApplication.applicationDefaultJvmArgs } startScripts.inputs.files project.objects.fileCollection().from { -> jar } } } protected void configureInstallTask(Project project) { - ApplicationPluginConvention pluginConvention = - (ApplicationPluginConvention) project.convention.plugins.application - project.tasks.named(SHADOW_INSTALL_TASK_NAME).configure { installTask -> installTask.doFirst { Sync task -> if (task.destinationDir.directory) { if (task.destinationDir.listFiles().size() != 0 && (!new File(task.destinationDir, 'lib').directory || !new File(task.destinationDir, 'bin').directory)) { - throw new GradleException("The specified installation directory '${task.destinationDir}' is neither empty nor does it contain an installation for '${pluginConvention.applicationName}'.\n" + + throw new GradleException("The specified installation directory '${task.destinationDir}' is neither empty nor does it contain an installation for '${javaApplication.applicationName}'.\n" + "If you really want to install to this directory, delete it and run the install task again.\n" + "Alternatively, choose a different installation directory." ) @@ -123,7 +105,7 @@ class ShadowApplicationPlugin implements Plugin { } } installTask.doLast { Sync task -> - project.ant.chmod(file: "${task.destinationDir.absolutePath}/bin/${pluginConvention.applicationName}", perm: 'ugo+x') + project.ant.chmod(file: "${task.destinationDir.absolutePath}/bin/${javaApplication.applicationName}", perm: 'ugo+x') } } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy index 3123bca5e..09a147d93 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy @@ -7,7 +7,7 @@ import org.gradle.api.attributes.Bundling import org.gradle.api.attributes.Category import org.gradle.api.attributes.LibraryElements import org.gradle.api.attributes.Usage -import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.tasks.SourceSetContainer import org.gradle.configuration.project.ProjectConfigurationActionContainer import org.gradle.util.GradleVersion @@ -55,7 +55,7 @@ class ShadowJavaPlugin implements Plugin { } protected void configureShadowTask(Project project) { - JavaPluginConvention convention = project.convention.getPlugin(JavaPluginConvention) + SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer) project.tasks.register(SHADOW_JAR_TASK_NAME, ShadowJar) { shadow -> shadow.group = SHADOW_GROUP shadow.description = 'Create a combined JAR of project and runtime dependencies' @@ -80,7 +80,7 @@ class ShadowJavaPlugin implements Plugin { manifest.attributes 'Class-Path': libs.findAll { it }.join(' ') } } - shadow.from(convention.sourceSets.main.output) + shadow.from(sourceSets.main.output) shadow.configurations = [project.configurations.findByName('runtimeClasspath') ? project.configurations.runtimeClasspath : project.configurations.runtime] shadow.exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'module-info.class')