From cd5210e22a8fb3f1eb937e4e2c4f3edb086528ad Mon Sep 17 00:00:00 2001 From: jameskleeh Date: Tue, 22 Aug 2017 11:58:32 -0400 Subject: [PATCH] Gradle 4 support --- build.gradle | 2 +- functional-tests-plugin/build.gradle | 2 +- functional-tests/build.gradle | 2 +- .../AbstractGroovyTemplateCompileTask.groovy | 3 + .../AbstractGroovyTemplatePlugin.groovy | 27 ++- gradle/wrapper/gradle-wrapper.properties | 1 + gradlew.bat | 180 +++++++++--------- 7 files changed, 118 insertions(+), 99 deletions(-) diff --git a/build.gradle b/build.gradle index 5c0569280..8318d310a 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ subprojects { userOrg = "grails" } group "org.grails" - version "1.2.4.BUILD_SNAPSHOT" + version "1.2.4.BUILD-SNAPSHOT" //version "1.2.3" repositories { mavenLocal() diff --git a/functional-tests-plugin/build.gradle b/functional-tests-plugin/build.gradle index 561cab1a3..9b613dd6d 100644 --- a/functional-tests-plugin/build.gradle +++ b/functional-tests-plugin/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "org.grails.plugins:views-gradle:1.0.8" + classpath "org.grails.plugins:views-gradle:1.2.3" } } diff --git a/functional-tests/build.gradle b/functional-tests/build.gradle index 5a4331014..fb4801cdf 100644 --- a/functional-tests/build.gradle +++ b/functional-tests/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "org.grails.plugins:views-gradle:1.0.8" + classpath "org.grails.plugins:views-gradle:1.2.3" classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.1.1' } } diff --git a/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy b/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy index 17544ba23..b8ce871bf 100644 --- a/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy +++ b/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplateCompileTask.groovy @@ -1,6 +1,7 @@ package grails.views.gradle import grails.io.ResourceUtils +import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import org.codehaus.groovy.tools.shell.util.PackageHelper import org.gradle.api.Action @@ -22,6 +23,7 @@ import org.gradle.process.JavaExecSpec */ @CompileStatic abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile { + @Input @Optional String packageName @@ -64,6 +66,7 @@ abstract class AbstractGroovyTemplateCompileTask extends AbstractCompile { ExecResult result = project.javaexec( new Action() { @Override + @CompileDynamic void execute(JavaExecSpec javaExecSpec) { javaExecSpec.setMain(getCompilerName()) javaExecSpec.setClasspath(getClasspath()) diff --git a/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy b/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy index ac9cefa3c..9ff56954e 100644 --- a/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy +++ b/gradle/src/main/groovy/grails/views/gradle/AbstractGroovyTemplatePlugin.groovy @@ -6,7 +6,10 @@ import org.apache.tools.ant.taskdefs.condition.Os import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.artifacts.Configuration import org.gradle.api.file.FileCollection +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetOutput import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.War import org.gradle.api.tasks.compile.GroovyCompile @@ -46,12 +49,12 @@ class AbstractGroovyTemplatePlugin implements Plugin { AbstractGroovyTemplateCompileTask templateCompileTask = (AbstractGroovyTemplateCompileTask)allTasks.create("compile${upperCaseName}Views".toString(), (Class)taskClass) - def mainSourceSet = SourceSets.findMainSourceSet(project) - def output = mainSourceSet?.output - def classesDir = output?.classesDir ?: new File(project.buildDir, "classes/main") - def destDir = new File(project.buildDir, "${templateCompileTask.fileExtension}-classes/main") + SourceSet mainSourceSet = SourceSets.findMainSourceSet(project) + SourceSetOutput output = mainSourceSet?.output + FileCollection classesDir = resolveClassesDirs(output, project) + File destDir = new File(project.buildDir, "${templateCompileTask.fileExtension}-classes/main") output?.dir(destDir) - def providedConfig = project.configurations.findByName('provided') + Configuration providedConfig = project.configurations.findByName('provided') FileCollection allClasspath @@ -66,7 +69,7 @@ class AbstractGroovyTemplatePlugin implements Plugin { } } - allClasspath = project.files(classesDir) + project.configurations.getByName('compile') + allClasspath = classesDir + project.configurations.getByName('compile') if(providedConfig) { allClasspath += providedConfig } @@ -93,4 +96,16 @@ class AbstractGroovyTemplatePlugin implements Plugin { } } } + + protected FileCollection resolveClassesDirs(SourceSetOutput output, Project project) { + FileCollection classesDirs + try { + classesDirs = output?.classesDirs ?: project.files(new File(project.buildDir, "classes/main")) + } + catch(e) { + classesDirs = output?.classesDir ? project.files(output.classesDir) : project.files(new File(project.buildDir, "classes/main")) + } + return classesDirs + } + } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fd05d3070..d12dcfc0c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -4,3 +4,4 @@ distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip + diff --git a/gradlew.bat b/gradlew.bat index 832fdb607..f6d5974e7 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,90 +1,90 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega