jdaugherty commented on code in PR #14816:
URL: https://github.com/apache/grails-core/pull/14816#discussion_r2150188684
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -644,77 +656,72 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
- // Set it on the extensions & spring boot extension "just" to be
complete in case any other tasks use these values
project.afterEvaluate {
- def extraProperties =
project.extensions.getByType(ExtraPropertiesExtension)
- extraProperties.set('mainClassName', project.provider {
- if (extraProperties.has('mainClassName')) {
- return extraProperties.get('mainClassName')
- }
-
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
+ // Support overrides - via mainClass property
+ def propertyMainClassName = project.findProperty('mainClass')
+ if(propertyMainClassName) {
+ findMainClassTask.configure {
+ it.mainClassName.set(propertyMainClassName)
}
+ }
- cacheFile?.text
- })
-
+ // Support overrides - via mainClass springboot extension
def springBootExtension =
project.extensions.getByType(SpringBootExtension)
- springBootExtension.mainClass.set(project.provider {
- if (springBootExtension.mainClass.isPresent()) {
- return springBootExtension.mainClass.get() as String
+ String springBootMainClassName =
springBootExtension.mainClass.getOrNull()
+ if(springBootMainClassName) {
+ findMainClassTask.configure {
+ it.mainClassName.set(springBootMainClassName)
}
+ }
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
+ if(springBootMainClassName && propertyMainClassName) {
+ if(springBootMainClassName != propertyMainClassName) {
+ throw new GradleException("If overriding the
mainClass, the property 'mainClass' and the springboot.mainClass must be set to
the same value")
}
+ }
+
+ def extraProperties =
project.extensions.getByType(ExtraPropertiesExtension)
+ def overriddenMainClass = propertyMainClassName ?:
springBootMainClassName
+ if(!overriddenMainClass) {
+ // the findMainClass task needs to set these values
+ extraProperties.set('mainClassName', project.provider {
+ File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
+ if (!cacheFile.exists()) {
+ return null
+ }
+
+ cacheFile?.text
+ })
- cacheFile?.text
- })
+ springBootExtension.mainClass.set(project.provider {
+ File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
+ if (!cacheFile.exists()) {
+ return null
+ }
+
+ cacheFile?.text
+ })
+ }
+ else {
+ // we need to set the overridden value on both
+ extraProperties.set('mainClass', overriddenMainClass)
+ springBootExtension.mainClass.set(overriddenMainClass)
+ }
}
project.tasks.withType(BootArchive).configureEach { BootArchive
bootTask ->
bootTask.dependsOn(findMainClassTask)
- bootTask.mainClass.convention(project.provider {
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
- }
-
- cacheFile?.text
- })
+
bootTask.mainClass.convention(GrailsGradlePlugin.getMainClassProvider(project))
Review Comment:
See previously
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -644,77 +656,72 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
- // Set it on the extensions & spring boot extension "just" to be
complete in case any other tasks use these values
project.afterEvaluate {
- def extraProperties =
project.extensions.getByType(ExtraPropertiesExtension)
- extraProperties.set('mainClassName', project.provider {
- if (extraProperties.has('mainClassName')) {
- return extraProperties.get('mainClassName')
- }
-
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
+ // Support overrides - via mainClass property
+ def propertyMainClassName = project.findProperty('mainClass')
+ if(propertyMainClassName) {
+ findMainClassTask.configure {
+ it.mainClassName.set(propertyMainClassName)
}
+ }
- cacheFile?.text
- })
-
+ // Support overrides - via mainClass springboot extension
def springBootExtension =
project.extensions.getByType(SpringBootExtension)
- springBootExtension.mainClass.set(project.provider {
- if (springBootExtension.mainClass.isPresent()) {
- return springBootExtension.mainClass.get() as String
+ String springBootMainClassName =
springBootExtension.mainClass.getOrNull()
+ if(springBootMainClassName) {
+ findMainClassTask.configure {
+ it.mainClassName.set(springBootMainClassName)
}
+ }
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
+ if(springBootMainClassName && propertyMainClassName) {
+ if(springBootMainClassName != propertyMainClassName) {
+ throw new GradleException("If overriding the
mainClass, the property 'mainClass' and the springboot.mainClass must be set to
the same value")
}
+ }
+
+ def extraProperties =
project.extensions.getByType(ExtraPropertiesExtension)
+ def overriddenMainClass = propertyMainClassName ?:
springBootMainClassName
+ if(!overriddenMainClass) {
+ // the findMainClass task needs to set these values
+ extraProperties.set('mainClassName', project.provider {
+ File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
+ if (!cacheFile.exists()) {
+ return null
+ }
+
+ cacheFile?.text
+ })
- cacheFile?.text
- })
+ springBootExtension.mainClass.set(project.provider {
+ File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
+ if (!cacheFile.exists()) {
+ return null
+ }
+
+ cacheFile?.text
+ })
+ }
+ else {
+ // we need to set the overridden value on both
+ extraProperties.set('mainClass', overriddenMainClass)
+ springBootExtension.mainClass.set(overriddenMainClass)
+ }
}
project.tasks.withType(BootArchive).configureEach { BootArchive
bootTask ->
bootTask.dependsOn(findMainClassTask)
- bootTask.mainClass.convention(project.provider {
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
- }
-
- cacheFile?.text
- })
+
bootTask.mainClass.convention(GrailsGradlePlugin.getMainClassProvider(project))
}
project.tasks.withType(BootRun).configureEach { BootRun it ->
it.dependsOn(findMainClassTask)
- it.mainClass.convention(project.provider {
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
- }
-
- cacheFile?.text
- })
+
it.mainClass.convention(GrailsGradlePlugin.getMainClassProvider(project))
Review Comment:
See previously
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -644,77 +656,72 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
- // Set it on the extensions & spring boot extension "just" to be
complete in case any other tasks use these values
project.afterEvaluate {
- def extraProperties =
project.extensions.getByType(ExtraPropertiesExtension)
- extraProperties.set('mainClassName', project.provider {
- if (extraProperties.has('mainClassName')) {
- return extraProperties.get('mainClassName')
- }
-
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
+ // Support overrides - via mainClass property
+ def propertyMainClassName = project.findProperty('mainClass')
+ if(propertyMainClassName) {
+ findMainClassTask.configure {
+ it.mainClassName.set(propertyMainClassName)
}
+ }
- cacheFile?.text
- })
-
+ // Support overrides - via mainClass springboot extension
def springBootExtension =
project.extensions.getByType(SpringBootExtension)
- springBootExtension.mainClass.set(project.provider {
- if (springBootExtension.mainClass.isPresent()) {
- return springBootExtension.mainClass.get() as String
+ String springBootMainClassName =
springBootExtension.mainClass.getOrNull()
+ if(springBootMainClassName) {
+ findMainClassTask.configure {
+ it.mainClassName.set(springBootMainClassName)
}
+ }
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
+ if(springBootMainClassName && propertyMainClassName) {
+ if(springBootMainClassName != propertyMainClassName) {
+ throw new GradleException("If overriding the
mainClass, the property 'mainClass' and the springboot.mainClass must be set to
the same value")
}
+ }
+
+ def extraProperties =
project.extensions.getByType(ExtraPropertiesExtension)
+ def overriddenMainClass = propertyMainClassName ?:
springBootMainClassName
+ if(!overriddenMainClass) {
+ // the findMainClass task needs to set these values
+ extraProperties.set('mainClassName', project.provider {
+ File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
+ if (!cacheFile.exists()) {
+ return null
+ }
+
+ cacheFile?.text
+ })
- cacheFile?.text
- })
+ springBootExtension.mainClass.set(project.provider {
+ File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
+ if (!cacheFile.exists()) {
+ return null
+ }
+
+ cacheFile?.text
+ })
+ }
+ else {
+ // we need to set the overridden value on both
+ extraProperties.set('mainClass', overriddenMainClass)
+ springBootExtension.mainClass.set(overriddenMainClass)
+ }
}
project.tasks.withType(BootArchive).configureEach { BootArchive
bootTask ->
bootTask.dependsOn(findMainClassTask)
- bootTask.mainClass.convention(project.provider {
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
- }
-
- cacheFile?.text
- })
+
bootTask.mainClass.convention(GrailsGradlePlugin.getMainClassProvider(project))
}
project.tasks.withType(BootRun).configureEach { BootRun it ->
it.dependsOn(findMainClassTask)
- it.mainClass.convention(project.provider {
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
- }
-
- cacheFile?.text
- })
+
it.mainClass.convention(GrailsGradlePlugin.getMainClassProvider(project))
}
project.tasks.withType(ResolveMainClassName).configureEach {
it.dependsOn(findMainClassTask)
-
- it.configuredMainClassName.set(project.provider {
- def springBootExtension =
project.extensions.getByType(SpringBootExtension)
- if (springBootExtension.mainClass.isPresent()) {
- return springBootExtension.mainClass.get() as String
- }
-
- File cacheFile =
findMainClassTask.get().mainClassCacheFile.orNull?.asFile
- if (!cacheFile.exists()) {
- return null
- }
-
- cacheFile?.text
- })
+
it.configuredMainClassName.convention(GrailsGradlePlugin.getMainClassProvider(project))
Review Comment:
See previously
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -797,13 +804,24 @@ class GrailsGradlePlugin extends GroovyPlugin {
@CompileDynamic
protected void configureRunScript(Project project) {
if (!project.tasks.names.contains('runScript')) {
- project.tasks.register('runScript',
ApplicationContextScriptTask).configure {
- SourceSet mainSourceSet = SourceSets.findMainSourceSet(project)
- it.classpath = mainSourceSet.runtimeClasspath +
project.configurations.getByName('console')
- it.systemProperty Environment.KEY,
System.getProperty(Environment.KEY, Environment.DEVELOPMENT.getName())
- def argsProperty = project.findProperty('args')
- if (argsProperty) {
-
it.args(CommandLineParser.translateCommandline(argsProperty))
+ def runTask = project.tasks.register('runScript',
ApplicationContextScriptTask)
+ project.afterEvaluate {
+ runTask.configure {
+ SourceSet mainSourceSet =
SourceSets.findMainSourceSet(project)
+ it.classpath = mainSourceSet.runtimeClasspath +
project.configurations.getByName('console')
+ it.systemProperty Environment.KEY,
System.getProperty(Environment.KEY, Environment.DEVELOPMENT.getName())
+ List<Object> args = []
+ def otherArgs = project.findProperty('args')
+ if (otherArgs) {
+
args.addAll(CommandLineParser.translateCommandline(otherArgs as String))
+ }
+
+ def appClassProvider =
GrailsGradlePlugin.getMainClassProvider(project)
Review Comment:
See previously
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]