├── .gitignore ├── CHANGELOG.md ├── README.md ├── build.gradle ├── gradle ├── docs.gradle ├── idea.gradle ├── publish.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── ideaCodeStyle.xml ├── src ├── docs │ ├── guide │ │ ├── advanced.gdoc │ │ ├── advanced │ │ │ ├── args.gdoc │ │ │ ├── debug.gdoc │ │ │ ├── env.gdoc │ │ │ ├── logging.gdoc │ │ │ ├── memory.gdoc │ │ │ ├── overview.gdoc │ │ │ └── plugins.gdoc │ │ ├── introduction.gdoc │ │ ├── introduction │ │ │ ├── changes.gdoc │ │ │ ├── commands.gdoc │ │ │ └── quickstart.gdoc │ │ ├── toc.yml │ │ ├── usage.gdoc │ │ └── usage │ │ │ ├── config.gdoc │ │ │ ├── deps.gdoc │ │ │ ├── init.gdoc │ │ │ ├── package.gdoc │ │ │ ├── run.gdoc │ │ │ ├── scripts.gdoc │ │ │ ├── test.gdoc │ │ │ └── upgrade.gdoc │ └── ref │ │ ├── Task Rules │ │ └── grails-.gdoc │ │ └── Tasks │ │ ├── init-plugin.gdoc │ │ ├── init.gdoc │ │ ├── packagePlugin.gdoc │ │ ├── run.gdoc │ │ ├── test.gdoc │ │ └── war.gdoc ├── main │ ├── groovy │ │ └── org │ │ │ └── grails │ │ │ └── gradle │ │ │ └── plugin │ │ │ ├── GrailsPlugin.groovy │ │ │ ├── GrailsProject.groovy │ │ │ ├── GrailsSourceSetConfigurator.groovy │ │ │ ├── dependencies │ │ │ ├── DependencyConfigurer.groovy │ │ │ ├── DependencyConfigurerFactory.groovy │ │ │ └── GrailsDependenciesConfigurer.groovy │ │ │ ├── eclipse │ │ │ └── GrailsEclipseConfigurator.groovy │ │ │ ├── idea │ │ │ └── GrailsIdeaConfigurator.groovy │ │ │ ├── internal │ │ │ ├── DefaultGrailsProject.groovy │ │ │ └── GrailsLaunchConfigureAction.java │ │ │ └── tasks │ │ │ ├── GrailsAssembleTask.groovy │ │ │ ├── GrailsEclipseJdtGroovyTask.groovy │ │ │ ├── GrailsInitTask.groovy │ │ │ ├── GrailsTask.groovy │ │ │ ├── GrailsTaskConfigurator.groovy │ │ │ └── GrailsTestTask.groovy │ └── resources │ │ ├── META-INF │ │ └── gradle-plugins │ │ │ └── grails.properties │ │ └── grails-maven │ │ └── log4j.properties └── test │ └── groovy │ └── org │ └── grails │ └── gradle │ └── plugin │ ├── IdeaConfigurationSpec.groovy │ ├── PluginSpec.groovy │ ├── TaskConfigurationSpec.groovy │ ├── dependencies │ └── GrailsDependenciesConfigurerSpec.groovy │ ├── eclipse │ └── GrailsEclipseConfiguratorSpec.groovy │ ├── integ │ ├── FailureSpec.groovy │ ├── IdeaSpec.groovy │ ├── InitSpec.groovy │ └── IntegSpec.groovy │ ├── internal │ └── GrailsLaunchConfigureActionSpec.groovy │ └── tasks │ └── GrailsEclipseJdtGroovyTaskSpec.groovy └── version.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | build/ 3 | bin/ 4 | .settings/ 5 | *.iml 6 | *.ipr 7 | *.iws 8 | .idea 9 | out 10 | *.orig 11 | /docs/ 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | See [Change Log](http://grails.github.io/grails-gradle-plugin/docs/manual/guide/introduction.html#changes) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Grails Gradle Plugin 2 | 3 | This plugin for Gradle allows you to build Grails projects. To use it, simply include the required JARs via `buildscript {}` and 'apply' the plugin: 4 | 5 | ```groovy 6 | buildscript { 7 | repositories { 8 | jcenter() 9 | } 10 | dependencies { 11 | classpath "org.grails:grails-gradle-plugin:2.1.2" 12 | } 13 | } 14 | 15 | version "0.1" 16 | group "example" 17 | 18 | apply plugin: "grails" 19 | 20 | repositories { 21 | grails.central() //creates a maven repo for the Grails Central repository (Core libraries and plugins) 22 | } 23 | 24 | grails { 25 | grailsVersion = '2.4.3' 26 | groovyVersion = '2.3.7' 27 | springLoadedVersion '1.2.0.RELEASE' 28 | } 29 | 30 | dependencies { 31 | bootstrap "org.grails.plugins:tomcat:7.0.50" // No container is deployed by default, so add this 32 | compile 'org.grails.plugins:asset-pipeline:2.1.3' // Just an example of adding a Grails plugin 33 | } 34 | ``` 35 | You must specify the `grails.grailsVersion` property before executing any Grails commands. 36 | 37 | The 'grails.groovyVersion' property is a convenience for Grails 2.3.0, it may not work correctly in earlier 38 | versions, so it's best to not use it with version pre-2.3.0. Declaring `grails.groovyVersion` will configure a Gradle ResolutionStrategy to modify all requests for `groovy-all` to be 39 | for the version specified. Additionally, the ResolutionStrategy will change all requests for `groovy` to be `groovy-all` 40 | 41 | The grails-gradle-plugin will populate the bootstrap, compile, and test classpaths with a base set of dependencies for Grails. 42 | You need to provide a container plugin such as 'tomcat' to the bootstrap classpath to enable the run-app command. 43 | 44 | *Warning* If you're using a pre-1.3.5 or pre-1.2.4 version of Grails, you'll need to add this runtime dependency to your project's build file: 45 | ```groovy 46 | runtime org.aspectj:aspectjrt:1.6.8 47 | ``` 48 | 49 | Once you have this build file, you can create a Grails application with the 'init' task: 50 | ```sh 51 | gradle init 52 | ``` 53 | 54 | Initialize a new Grails plugin project by running: 55 | ```sh 56 | gradle init-plugin 57 | ``` 58 | 59 | The plugin creates standard tasks that mimic the Java lifecycle: 60 | 61 | * clean 62 | * test 63 | * check 64 | * build 65 | * assemble 66 | 67 | These tasks are wrapper tasks that declare a `dependsOn` to Grails specific tasks. This will allow for further build customization. 68 | 69 | * clean [grails-clean] 70 | * test [grails-test] 71 | * assemble [grails-war or grails-package-plugin] 72 | 73 | You can also access any Grails command by prefixing it with `grails-`. For example, to run the application: 74 | ```sh 75 | gradle grails-run-app 76 | ``` 77 | If you want to pass in some arguments, you can do so via the `grailsArgs` project property: 78 | ```sh 79 | gradle -PgrailsArgs='--inplace solr' grails-create-plugin 80 | ``` 81 | You can also change the environment via the `env` project property: 82 | ```sh 83 | gradle -PgrailsEnv=prod grails-run-app 84 | ``` 85 | You can execute multiple Grails commands in a single step, but bear in mind that if you are passing `grailsEnv` or `grailsArgs` then each of the 86 | commands will execute with the same values. 87 | 88 | ## Troubleshooting 89 | 90 | * `Caused by: org.apache.tools.ant.BuildException: java.lang.NoClassDefFoundError: org/apache/commons/cli/Options` 91 | 92 | This happens if your project depends on the `groovy` JAR rather than `groovy-all`. Change your dependency to the latter and all will be well. 93 | 94 | * Classloading issues, casting proxy instances to their corresponding interface 95 | 96 | This can be a sign of a corrupted Spring-Loaded cache directory. The plugin has spring-loaded cache in `$HOME/.grails/.slcache` - try cleaning that directory 97 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | group = 'org.grails' 4 | version = file('version.txt').text.trim() 5 | archivesBaseName = 'grails-gradle-plugin' 6 | 7 | sourceCompatibility = '1.6' 8 | 9 | repositories { 10 | maven { url 'http://repo.grails.org/grails/libs-snapshots-local' } 11 | maven { url 'http://repo.grails.org/grails/repo' } 12 | } 13 | 14 | dependencies { 15 | compile gradleApi() 16 | compile localGroovy() 17 | 18 | compile 'org.grails:grails-launcher:1.1' 19 | testCompile 'org.spockframework:spock-core:0.7-groovy-1.8', { 20 | exclude module: 'groovy-all' 21 | } 22 | } 23 | 24 | apply from: 'gradle/publish.gradle' 25 | apply from: 'gradle/idea.gradle' 26 | apply from: 'gradle/docs.gradle' 27 | -------------------------------------------------------------------------------- /gradle/docs.gradle: -------------------------------------------------------------------------------- 1 | import grails.doc.DocPublisher 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'org.grails:grails-docs:2.3.6' 9 | } 10 | } 11 | 12 | task sourcesJar(type: Jar) { 13 | classifier "sources" 14 | from sourceSets.main.allSource 15 | } 16 | 17 | task javadocJar(type: Jar) { 18 | classifier "javadoc" 19 | from javadoc 20 | } 21 | 22 | artifacts { 23 | archives sourcesJar, javadocJar 24 | } 25 | 26 | task gdocs() { 27 | group 'Documentation' 28 | description 'Generate Grails Doc style documentation' 29 | doLast { 30 | def srcDocs = file("src/docs") 31 | def outputDir = file("docs/manual") 32 | def publisher = new DocPublisher(srcDocs, outputDir) 33 | publisher.with { 34 | ant = project.ant 35 | title = 'Grails Gradle Plugin' 36 | subtitle = 'Grails Gradle Plugin' 37 | version = project.version 38 | authors = 'Luke Daley, Graeme Rocher, Peter Ledbrook, John Engelman' 39 | license = 'The Apache Software License, Version 2.0' 40 | copyright = '' 41 | footer = '' 42 | engineProperties = [:] 43 | } 44 | publisher.publish() 45 | } 46 | } -------------------------------------------------------------------------------- /gradle/idea.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'idea' 2 | 3 | idea { 4 | project { 5 | jdkName "1.6" 6 | ipr { 7 | withXml { provider -> 8 | def node = provider.asNode() 9 | node.component.find { it.'@name' == 'VcsDirectoryMappings' }?.mapping[0].'@vcs' = 'Git' 10 | node.append(new XmlParser().parse(file("ideaCodeStyle.xml"))) 11 | 12 | def copyrightManager = node.component.find { it.'@name' == 'CopyrightManager' } 13 | copyrightManager.@default = "ASL2" 14 | def aslCopyright = copyrightManager.copyright.find { it.option.find { it.@name == "myName" }?.@value == "ASL2" } 15 | if (aslCopyright == null) { 16 | copyrightManager.append(new XmlParser().parseText(''' 17 | 18 | 24 | ''')) 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /gradle/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'signing' 2 | apply plugin: 'maven' 3 | 4 | signing { 5 | sign configurations.archives 6 | } 7 | 8 | def poms = [project.install.repositories.mavenInstaller.pom] 9 | 10 | uploadArchives { task -> 11 | poms << repositories.mavenDeployer { 12 | beforeDeployment { MavenDeployment deployment -> 13 | signing.signPom(deployment) 14 | } 15 | 16 | gradle.taskGraph.whenReady { taskGraph -> 17 | if (taskGraph.hasTask(task)) { 18 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") { 19 | authentication(userName: sonatypeOssUsername, password: sonatypeOssPassword) 20 | } 21 | snapshotRepository(url: "http://repo.grails.org/grails/libs-snapshots-local") { 22 | authentication(userName: grailsRepoUsername, password: grailsRepoPassword) 23 | } 24 | } 25 | } 26 | }.pom 27 | } 28 | 29 | poms*.whenConfigured { 30 | it.project { 31 | name 'Grails Gradle Plugin' 32 | packaging 'jar' 33 | description 'Gradle plugin for Grails' 34 | url 'http://grails.org/' 35 | 36 | licenses { 37 | license { 38 | name 'The Apache Software License, Version 2.0' 39 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 40 | distribution 'repo' 41 | } 42 | } 43 | 44 | scm { 45 | delegate.url 'scm:git@github.com:grails/grails-gradle-plugin.git' 46 | connection 'scm:git@github.com:grails/grails-gradle-plugin.git' 47 | developerConnection 'scm:git@github.com:grails/grails-gradle-plugin.git' 48 | } 49 | 50 | licenses { 51 | license { 52 | name 'The Apache Software License, Version 2.0' 53 | delegate.url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 54 | distribution 'repo' 55 | } 56 | } 57 | 58 | developers { 59 | developer { 60 | id 'alkemist' 61 | name 'Luke Daley' 62 | } 63 | developer { 64 | id 'graemerocher' 65 | name 'Graeme Rocher' 66 | } 67 | developer { 68 | id 'pledbrook' 69 | name 'Peter Ledbrook' 70 | } 71 | developer { 72 | id 'johnrengelman' 73 | name 'John Engelman' 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grails/grails-gradle-plugin-archived/a961eec8e87b6279bc1e367a0910e5bd97dda79d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 03 08:16:26 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /ideaCodeStyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 | 29 | -------------------------------------------------------------------------------- /src/docs/guide/advanced.gdoc: -------------------------------------------------------------------------------- 1 | This section covers advanced topics in the Gradle Grails Plugin. It includes topics related to configuring the 2 | underlying JVM that is executing the Grails tasks and integrating Grails builds into larger multi-project build. -------------------------------------------------------------------------------- /src/docs/guide/advanced/args.gdoc: -------------------------------------------------------------------------------- 1 | The plugin tries to configure the known Grails tasks to the best of its abilities. However, sometimes additional 2 | parameters are necessary to be be passed from the command line. In order to pass options to the underlying JVM that 3 | is forked using the @grailsArgs@ system property from the command line: 4 | 5 | {code} 6 | $ gradle -PgrailsArgs="FooController" grails-create-controller 7 | {code} 8 | 9 | The above line with pass the @FooController@ string to the underlying Grails @create-controller@ command. 10 | 11 | {note} 12 | The @grailsArgs@ property is a single system property. You can only specify it once and it is not parsed in anyway before 13 | being passed to the Grails JVM. It is strongly recommended to use "" around the value being passed to avoid any type of 14 | shell interpretation of the value. 15 | {note} 16 | 17 | {note} 18 | The @grailsArgs@ property is wired *ONLY* to dynamically created tasks using the @grails-@ prefix. Tasks created by 19 | the plugin are intended to provide for a repeatable build experience and as such do *NOT* accept additional parameters 20 | via the command line. The proper way to configure these tasks is via the Gradle build file 21 | {note} -------------------------------------------------------------------------------- /src/docs/guide/advanced/debug.gdoc: -------------------------------------------------------------------------------- 1 | The plugin allows Grails tasks to enable a debugger by setting the @grailsDebug@ property to @true@. 2 | 3 | {code} 4 | $ gradle -PgrailsDebug="true" run 5 | {code} 6 | 7 | The above command will execute the Grails @run-app@ command with debug mode activated. This flag sets the debug mode 8 | by setting @jvmOptions.debug=true@ on the underlying Gradle @JavaExec@ instance for the Grails task. By default this 9 | activates debugging in a suspended mode on port 5005. 10 | 11 | {note} 12 | The @grailsDebug@ is passed to *ALL* Grails tasks in Gradle. 13 | {note} 14 | 15 | To manually configure the debug properties (i.e., suspend mode, port, etc) for the tasks, 16 | configure the options via the @jvmOptions.jvmArgs@ property: 17 | 18 | {code} 19 | run { 20 | jvmOptions { 21 | jvmArgs([ 22 | '-Xdebug', 23 | '-Xnoagent', 24 | '-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006' 25 | ]) 26 | } 27 | } 28 | {code} 29 | 30 | The above block configures the JVM that Grails executes in to have a remote debugger on port 5006 and does *NOT* 31 | suspend the JVM on startup. 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/docs/guide/advanced/env.gdoc: -------------------------------------------------------------------------------- 1 | The plugin allows you to override the Grails environment on the command line by using the @grailsEnv@ property on the 2 | command line: 3 | 4 | {code} 5 | $ gradle -PgrailsEnv=prod grails-run-app 6 | {code} 7 | 8 | The above command will execute the Grails @run-app@ command in the @prod@ environment. 9 | 10 | {note} 11 | The @PgrailsEnv@ property is wired *ONLY* to dynamically created tasks using the @grails-@ prefix. Tasks created by 12 | the plugin are intended to provide for a repeatable build experience and as such do *NOT* accept additional parameters 13 | via the command line. The proper way to configure these tasks is via the Gradle build file 14 | {note} -------------------------------------------------------------------------------- /src/docs/guide/advanced/logging.gdoc: -------------------------------------------------------------------------------- 1 | By default @GrailsTask@s will send their output and error stream to @System.out@ and @System.err@ respectively. 2 | However, any task can be configured to instead capture their output to the @Logger.INFO@ level by setting the 3 | @captureOutputToInfo@ property to @true@ on the task. When enabled, the task will capture its output and error streams 4 | to a buffer. If the task encounters an error, then both the output and error streams will be rendered onto @System.out@ 5 | and @System.err@ respectively. 6 | 7 | This allows a successful build to minimize the amount of logging produced to the console during the build and also 8 | allows the output from failed tasks in a parallel multi-project build to rendered their output without interleaving 9 | it with the output of other tasks. 10 | 11 | The property can be configured on all @GrailsTask@ instances using the following: 12 | 13 | {code} 14 | project.tasks.withType(GrailsTask) { 15 | captureOutputToInfo = true 16 | } -------------------------------------------------------------------------------- /src/docs/guide/advanced/memory.gdoc: -------------------------------------------------------------------------------- 1 | Grails applications are known for quickly growing in memory size (especially in PermGen). Currently, the plugin makes 2 | no efforts to configure the memory settings for the Grails JVM. By default then, the Grails JVM will have the same 3 | memory settings as the Gradle JVM which forked it. 4 | 5 | Each @GrailsTask@ exposes a @jvmOptions@ property that can be used to configure the underlying JVM. The @jvmOptions@ 6 | property is an instance of "JavaForkOptions":http://www.gradle.org/docs/current/javadoc/org/gradle/process/JavaForkOptions.html 7 | and all the properties and methods from that class are available. 8 | 9 | {code} 10 | run { 11 | jvmOptions { 12 | minHeapSize = '512m' 13 | maxHeapSize = '1g' 14 | jvmArgs '-XX:MaxPermSize=512m' 15 | } 16 | } 17 | {code} 18 | 19 | Alternatively, it may be beneficial to configure all the @GrailsTask@ in the build to have the same memory settings. 20 | 21 | {code} 22 | project.tasks.withType(GrailsTask) { GrailsTask task -> 23 | task.jvmOptions { 24 | minHeapSize = '512m' 25 | maxHeapSize = '1g' 26 | jvmArgs '-XX:MaxPermSize=512m' 27 | } 28 | } 29 | {code} -------------------------------------------------------------------------------- /src/docs/guide/advanced/overview.gdoc: -------------------------------------------------------------------------------- 1 | Integration of Grails into Gradle via this plugin is a complicated endeavour. The Grails framework contains its own 2 | build tooling that performs source compilation, test execution, and artifact packaging. Additionally, it has an extensive 3 | and mature plugin community of its own. Each plugin can add its own scripts to a Grails build and provide additional 4 | dependencies. 5 | 6 | Because Grails contains is own build tooling, Grails projects, despite being based on Java & Groovy, do *NOT* use 7 | the Groovy, Java, or War plugins for Gradle. As a consequence, these projects lose many of the conveniences for 8 | configuration that a standard Gradle project would receive. The Gradle Grails Plugin tries to address many of these 9 | shortcomings but some may not be possible with the current state of the frameworks. 10 | 11 | {note} 12 | The Grails 3 Road Map currently includes re-writing the Grails build system to be based on Gradle. 13 | {note} 14 | 15 | The Grails Gradle Plugin integrates with Grails through another library "Grails Launcher":https://github.com/grails/grails-launcher. 16 | This library functions by creating a @LaunchContext@ instance that contains the necessary classpath information, 17 | script name, and arguments and serializing it to disk in a known location. Gradle then forks a JVM instance that will 18 | execute the @Main@ class in the Grails Launcher project with the path to the serialized @LaunchContext@. 19 | 20 | The Grails Launcher project is a library that integrates at a low-level into the Grails framework. In short, it 21 | configures the JVM is the same manner that the @grails@ scripts on the command line do when executing Grails natively. -------------------------------------------------------------------------------- /src/docs/guide/advanced/plugins.gdoc: -------------------------------------------------------------------------------- 1 | The plugin configures the @build@ task to call the appropriate @package-plugin@ task for Grails plugin projects to produce 2 | the plugin zip file. Additionally, the plugin configures the Gradle configuration inheritance so that including Grails 3 | plugin projects via a Gradle @project@ dependency should include the transitive dependencies for the plugin. 4 | 5 | h4. Plugin Publication 6 | 7 | {warning} 8 | Plugin Publication is not fully supported at this time. Additional information will be added to this page as use cases 9 | are defined. 10 | {warning} 11 | 12 | h5. Publishing a Simple Grails Plugin 13 | 14 | For simple Grails plugin projects, that is projects that have *NO* external dependencies, plugin release and publication 15 | can be accomplished using the "Grails Release Plugin":http://grails.org/plugin/release. Add the @release@ plugin to 16 | the @bootstrap@ configuration and execute the @grails-release-plugin@ task. 17 | 18 | {code} 19 | dependencies { 20 | bootstrap 'org.grails.plugin:release:2.2.1' 21 | } 22 | 23 | $ gradle grails-release-plugin 24 | {code} 25 | 26 | {warning} 27 | See the plugin page http://grails.org/plugin/release for compatibility notes regarding the release plugin and the Grails version 28 | {warning} 29 | 30 | {note} 31 | Using the Release Plugin is only supported when there are no external dependencies because the @release-plugin@ command 32 | utilizes the dependencies configured in @BuildConfig.groovy@ to build the plugin's @pom.xml@ file. Since dependencies 33 | are being configure through Gradle, the @BuildConfig.groovy@ will not have the correct information and the @pom.xml@ 34 | will be incorrect (especially when using Gradle @project@ dependencies). 35 | {note} 36 | 37 | h5. Publishing Using the Gradle Maven Plugin 38 | 39 | Plugin publication using the "@maven@":http://www.gradle.org/docs/current/userguide/artifact_management.html plugin is 40 | currently untested. 41 | 42 | h5. Publishing Using the Gradle Maven-Publish (incubating) Plugin 43 | 44 | Plugin publication using the "@maven-publish@":http://www.gradle.org/docs/current/userguide/publishing_maven.html plugin 45 | is not fully supported. This is an incubating plugin and dependency information is not generated correctly in the POM. 46 | Specifically, at the time of writing, all dependencies were added to the @runtime@ scope in the POM and installing the 47 | resulting plugin in a project did not resolve transitive dependencies correctly. -------------------------------------------------------------------------------- /src/docs/guide/introduction.gdoc: -------------------------------------------------------------------------------- 1 | The Grails Gradle Plugin provides integration of Grails applications into the Gradle framework. In simple terms, 2 | this plugin allows Gradle to build Grails applications in a compatible way with the internal build tooling of the 3 | Grails framework. 4 | -------------------------------------------------------------------------------- /src/docs/guide/introduction/changes.gdoc: -------------------------------------------------------------------------------- 1 | h4. 2.2.0 2 | 3 | * Add support for Eclipse/GGTS IDE integration. Thanks to "jeevatkm":https://github.com/jeevatkm 4 | * Support Gradle 2.3 - "ISSUE-136":https://github.com/grails/grails-gradle-plugin/issues/136 - Actual fix is provided by the Eclipse/GGTS IDE integration 5 | * Add @ignoreFailures@ support to @GrailsTestTask@ tasks. Thanks to "omerozkan":https://github.com/omerozkan 6 | 7 | h4. 2.1.2 8 | 9 | * Support Gradle 2.2 - "ISSUE-128":https://github.com/grails/grails-gradle-plugin/issues/128 10 | 11 | h4. 2.1.1 12 | 13 | * Configure @war@ task to use @production@ environment by default - "ISSUE-101":https://github.com/grails/grails-gradle-plugin/issues/101 14 | * Handle No signature of method: LinePerThreadBufferingOutputStream.writeTo(LinePerThreadBufferingOutputStream) error - "ISSUE-120":https://github.com/grails/grails-gradle-plugin/issues/120 15 | * Add @captureOutputToInfo@ property to @GrailsTask@ which properly captures streams to INFO logger unless error occurs. Disabled by default 16 | 17 | h4. v2.1.0 18 | 19 | * Renamed default tasks created by plugin: - "ISSUE-81":https://github.com/grails/grails-gradle-plugin/issues/81 20 | ** @run@ replaces @grails-run-app@ 21 | ** @test@ replaces @grails-test-app@ 22 | ** @war@ replaces @grails-war@ 23 | ** @packagePlugin@ replaces @grails-package-plugin@ 24 | * Added the @reload@ property @GrailsTask@ to enabled SpringLoaded class reloading for a task. - "ISSUE-84": https://github.com/grails/grails-gradle-plugin/issues/84 25 | * Configure the static @run@ task and dynamic @grails-run-app@ task to enabled reloading by default. 26 | * Removed creating the @grails-clean@ task by default. Configure the normal @clean@ task to delete the @buildPlugins/@ directory. 27 | * Fix a bug in the IntelliJ IDEA integration where only 1 plugin per configuration was being registered as project source 28 | * Include bootstrap scope plugins as project source in IntelliJ IDEA 29 | * Mark test scope plugins directories as Test Source instead of Source in IntelliJ IDEA 30 | * Support new Maven group name for SpringLoaded library starting with v1.1.5.RELEASE 31 | * Add support to automatically synchronize @app.version@ and @app.grails.version@ in the @application.properties@ 32 | file to @project.version@ and @project.grails.grailsVersion@ respectively - "MAVEN-137":http://jira.grails.org/browse/MAVEN-137 33 | * Correctly mapped @provided@ scope dependencies to the Grails environment 34 | * Allow passing of the @-PgrailsDebug=true@ flag to all Grails tasks. - "ISSUE-97":https://github.com/grails/grails-gradle-plugin/issues/97 35 | 36 | h4. v2.0.1 37 | 38 | * Fix a bug in setting @grails.groovyVersion@ which resulted in an exception when a dependency tried to include the groovy library. 39 | * Fix a bug where when a @GrailsTestTask@ is configured with both a set of Task Inputs and a @testResultsDir@ that results in an exception because @testResultsDir@ is a directory but Gradle expects it to be a file. 40 | * Fix a bug in the task dependency configuration for the @clean@ task that results in Gradle being unable to determine the task graph. 41 | * Add plugin Zip file or application War file as an output file to the runtime configuration. 42 | * Configured the default configuration to extend from runtime (similar to Java plugin behavior) 43 | * Springloaded is only configured for the @grails-run-app@ task (this is what Grails itself does in @grailsStart@ script). 44 | * Added the @init-plugin@ task to initialize a Grails plugin instead of an application. 45 | * The @grails-run-app@ task is now available on plugin projects as well (Grails allows this) -------------------------------------------------------------------------------- /src/docs/guide/introduction/commands.gdoc: -------------------------------------------------------------------------------- 1 | Applying the plugin creates the following default tasks in the Gradle project. Task dependencies are declared in brackets. 2 | 3 | * @run@ 4 | * @test@ 5 | * @war@ 6 | * @packagePlugin@ 7 | 8 | Additionally, the plugin creates set of default Gradle tasks to mimic the behavior of a standard Gradle Java project. 9 | These tasks are wired to the corresponding @GrailsTask@ to provide the behavior. 10 | 11 | * @clean@ 12 | * @test@ 13 | * @check@ \[@test@\] 14 | * @assemble@ \[@war@ or @packagePlugin@\] 15 | * @build@ \[@assemble@, @check@\] 16 | 17 | Finally, the plugin creates a Gradle Task Rule that allows for execution of any arbitrary Grails script by prefixing 18 | the script name with @grails-@ 19 | {code} 20 | $ gradle grails-s2-quickstart //Execute the s2-quickstart script from the Spring Security Core plugin 21 | {code} -------------------------------------------------------------------------------- /src/docs/guide/introduction/quickstart.gdoc: -------------------------------------------------------------------------------- 1 | The following @build.gradle@ example shows a Grails application configuration in Gradle that matches the default configuration 2 | generated by Grails for new projects. Not all the dependencies are required for every application. 3 | 4 | {code} 5 | buildscript { 6 | repositories { 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'org.grails:grails-gradle-plugin:2.2.0.RC1' 11 | } 12 | } 13 | 14 | apply plugin: 'grails' 15 | 16 | grails { 17 | grailsVersion = '2.4.4' // Specifies the Grails version to use 18 | groovyVersion = '2.3.7' // Specify the Groovy version to use (should match the version that ships with the above Grails version) 19 | springLoadedVersion = '1.2.0.RELEASE' // Specify the Spring Loaded version to use 20 | } 21 | 22 | repositories { 23 | jcenter() 24 | grails.central() //Adds the Grails Central Repository for resolving Grails plugins (replaces grailsPlugins(), grailsCentral() from BuildConfig.groovy) 25 | } 26 | 27 | dependencies { 28 | bootstrap 'org.grails.plugins:tomcat:7.0.50.1' 29 | 30 | compile 'org.grails.plugins:scaffolding:2.1.2' 31 | compile 'org.grails.plugins:cache:1.1.8' 32 | 33 | runtime 'org.grails.plugins:hibernate:3.6.10.8' //or 'org.grails.plugins:hibernate4:4.3.1.1' 34 | runtime 'org.grails.plugins:database-migration:1.3.8' 35 | runtime 'org.grails.plugins:jquery:1.11.0' 36 | 37 | //runtime 'mysql:mysql-connector-java:5.1.24' 38 | //runtime 'org.postgresql:postgresql:9.3.1100-jdbc41' 39 | 40 | //Additional resources capabilities 41 | //runtime 'org.grails.plugins:zipped-resources:1.0.1' 42 | //runtime 'org.grails.plugins:cached-resources:1.1' 43 | //runtime 'org.grails.plugins:yui-minify-resources:0.1.5' 44 | 45 | //compile 'org.grails.plugins:asset-pipeline:2.1.3' 46 | 47 | //Additional asset-pipeline capabilities 48 | //compile 'org.grails.plugins:sass-asset-pipeline:1.5.1' 49 | //compile 'org.grails.plugins:less-asset-pipeline:1.5.0' 50 | //compile 'org.grails.plugins:coffee-asset-pipeline:1.5.0' 51 | //compile 'org.grails.plugins:handlebars-asset-pipeline:1.0.0.3' 52 | } 53 | {code} 54 | 55 | {warning} 56 | If you are using a version of Grails that is < @1.3.5@ or @1.2.4@, the following @runtime@ dependency *MUST* be added: 57 | {code} 58 | runtime 'org.aspectj:aspectjrt:1.6.8' 59 | {code} 60 | {warning} 61 | -------------------------------------------------------------------------------- /src/docs/guide/toc.yml: -------------------------------------------------------------------------------- 1 | introduction: 2 | title: Introduction 3 | quickstart: Quick Start 4 | commands: Basic Task Reference 5 | changes: Change Log 6 | usage: 7 | title: Using the Plugin 8 | init: Initializing a Grails Project 9 | deps: Configuring Project Dependencies 10 | run: Running a Grails Project 11 | test: Running Tests 12 | scripts: Executing Grails Scripts 13 | package: Packaging a Grails Project 14 | config: Configuring Plugin Properties 15 | upgrade: Upgrading a Grails Application 16 | advanced: 17 | title: Advanced Plugin Configuration & Usage 18 | overview: Overview of Plugin Integration with Grails 19 | args: Passing arguments to Grails Tasks 20 | env: Setting the Grails Environment 21 | debug: Debugging Grails tasks 22 | memory: Configuring JVM Memory for Grails Tasks 23 | logging: Capturing Grails task output to INFO log 24 | plugins: Managing Grails Plugins with Gradle -------------------------------------------------------------------------------- /src/docs/guide/usage.gdoc: -------------------------------------------------------------------------------- 1 | The Grails Gradle Plugin is available from Bintray's JCenter and the Maven Central repositories. Apply it to a Gradle 2 | project the same way as any other plugin: 3 | 4 | {code} 5 | buildscript { 6 | repositories { 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'org.grails:grails-gradle-plugin:2.1.2' 11 | } 12 | } 13 | 14 | apply plugin: 'grails' 15 | 16 | version = 1.0 17 | 18 | grails { 19 | grailsVersion = '2.3.6' 20 | groovyVersion = '2.1.9' 21 | } 22 | 23 | repositories { 24 | grails.central() 25 | } 26 | {code} 27 | 28 | {note} 29 | The plugin requires that the @grails.grailsVersion@ is specified for the project. Additionally, the @version@ property 30 | is required for executing the @init@ task since Grails needs the application version during project initialization. 31 | {note} 32 | 33 | {note} 34 | While the @grails.groovyVersion@ property is not required, specifying it allows the plugin to properly configure the 35 | Groovy runtime for the @bootstrap@ and @compile@ classpaths. Additionally, specifying it will configure a Gradle 36 | @ResolutionStrategy@ to prevent different versions of @groovy@ or @groovy-all@ from entering the classpath through 37 | dependencies. 38 | {note} 39 | 40 | {note} 41 | If you are using the Grails Gradle Plugin to build applications with a version of Grails prior to 2.3.0, configuring the 42 | @grails.groovyVersion@ property may have some side effects. 43 | {note} 44 | 45 | {warning} 46 | Specifying a @grails.groovyVersion@ that does not match the Groovy version supplied with the specified @grails.grailsVersion@ 47 | is not supported. It is possible to make this configuration, but unforeseen behavior may occur. 48 | {warning} -------------------------------------------------------------------------------- /src/docs/guide/usage/config.gdoc: -------------------------------------------------------------------------------- 1 | The plugin provides a number of properties that can be configure for each build. These properties are configure 2 | through the @grails@ extension in the Gradle build: 3 | 4 | {code} 5 | grails { 6 | grailsVersion = '2.3.6' 7 | groovyVersion = '2.1.9' 8 | springLoadedVersion = '1.1.3' 9 | } 10 | {code} 11 | 12 | h4. GrailsVersion 13 | 14 | The @grailsVersion@ property specifies the version of Grails to build the application against. This will transitively 15 | include a number of Grails libraries onto the classpath for compilation. 16 | 17 | h4. GroovyVersion 18 | 19 | The @groovyVersion@ property specifies the version of Groovy to use to build the application. This is a convenience method. 20 | By setting this property, the plugin will add the specified version of the @groovy-all@ library to both the @boot@ and 21 | @compile@ configurations. Additionally, it will configure a @ResolutionStrategy@ rule to convert all requests for @groovy-all@ 22 | to use this version for the dependency and all requests for the standard @groovy@ library will be converted to request 23 | the @groovy-all@ library instead. 24 | 25 | {note} 26 | If you are using the Grails Gradle Plugin to build applications with a version of Grails prior to 2.3.0, configuring the 27 | @grails.groovyVersion@ property may have some side effects. 28 | {note} 29 | 30 | {warning} 31 | Specifying a @grails.groovyVersion@ that does not match the Groovy version supplied with the specified @grails.grailsVersion@ 32 | is not supported. It is possible to make this configuration, but unforeseen behavior may occur. 33 | {warning} 34 | 35 | h4. SpringLoadedVersion 36 | 37 | The @springLoadedVersion@ property specifies the version of the SpringLoaded library to place on the classpath when 38 | executing the @run@ or @grails-run-app@ tasks. This library enables class reloading. Internally, the plugin configures a 39 | Java Agent using this library which performs the reload in the JVM. The plugin configures a default version of the library, 40 | and this property can be used to specify a different version than the default. 41 | 42 | By default, the plugin only configures the springLoaded library and reloading on the @run@ and @grails-run-app@ tasks. -------------------------------------------------------------------------------- /src/docs/guide/usage/deps.gdoc: -------------------------------------------------------------------------------- 1 | Using the Grails Gradle Plugin bypasses the normal Grails application build framework in favor of Gradle. The consequence 2 | of this is that the @BuildConfig.groovy@ is no longer consulted for repository or dependency information. All repositories 3 | and dependencies *MUST* be configured via Gradle. 4 | 5 | {note} 6 | Because Grails is no longer resolving the dependency information, the short syntax for plugins cannot be used: 7 | 8 | {code} 9 | plugins { 10 | compile ':resources:1.1.1' 11 | } 12 | {code} 13 | 14 | In Grails, the syntax omits the Maven groupId for Grails plugins because all public Grails plugins are published under 15 | the @org.grails.plugins@ groupId. With Gradle, the groupId *MUST* be specified: 16 | 17 | {code} 18 | dependencies { 19 | compile 'org.grails.plugins:resources:1.1.1' 20 | } 21 | {code} 22 | {note} 23 | 24 | The Grails Gradle Plugin configures the following scopes for dependency resolution: @bootstrap@, @provided@, @compile@, 25 | @runtime@, @test@. These scopes map to the same scopes normally used in @BuildConfig.groovy@. -------------------------------------------------------------------------------- /src/docs/guide/usage/init.gdoc: -------------------------------------------------------------------------------- 1 | Once the plugin is applied, a new Grails project can be initialized through Gradle. 2 | 3 | {code} 4 | $ gradle init //Initializes a Grails application 5 | {code} 6 | 7 | OR 8 | 9 | {code} 10 | $ gradle init-plugin //Initializes a Grails plugin 11 | {code} 12 | 13 | Both tasks initialize the Grails project in the current working directory. 14 | 15 | {note} 16 | The plugin initializes the application/plugin with the name of the Gradle project and the current Gradle project version 17 | {note} -------------------------------------------------------------------------------- /src/docs/guide/usage/package.gdoc: -------------------------------------------------------------------------------- 1 | The Grails Gradle Plugin configures the normal Gradle @assemble@ task to execute the appropriate Grails command for 2 | creating the project's output. For applications, the @assemble@ task depends on @war@ which executes the Grails @war@ 3 | script and produces a War output. 4 | For plugins, the @assemble@ task depends on @packagePlugin@ which executes the Grails @package-plugin@ script 5 | and produces the plugin Zip output. 6 | 7 | Additionally, the plugin configures the normal Gradle @build@ task to depend on @test@ and @assemble@ -------------------------------------------------------------------------------- /src/docs/guide/usage/run.gdoc: -------------------------------------------------------------------------------- 1 | The Grails Gradle Plugin creates a @run@ task on the project that will start the Grails application container 2 | in the normal development environment by executing the Grails @run-app@ script. 3 | 4 | {code} 5 | $ gradle run 6 | {code} 7 | 8 | Grails does not ship with an application container provided, so the build must specify a Grails plugin dependency. Typically, 9 | this will be the Grails tomcat plugin: 10 | 11 | {code} 12 | dependencies { 13 | bootstrap 'org.grails.plugins:tomcat:7.0.50' 14 | } 15 | {code} 16 | 17 | By default, the plugin configures the @run@ task and dynamic @grails-run-app@ task to enabled class reloading via 18 | SpringLoaded. Other other tasks created by the plugin or dynamically created via the Grails Script pattern will 19 | have reloading disabled. To enable reloading for @GrailsTask@, define the task and configure the @reload@ property 20 | to @true@. 21 | 22 | {note} 23 | Running the @run@ task will prevent the Gradle execution from completing (i.e. the task blocks on the running container). 24 | To terminate the Grails application, use Ctrl+C to terminate the Gradle run 25 | {note} -------------------------------------------------------------------------------- /src/docs/guide/usage/scripts.gdoc: -------------------------------------------------------------------------------- 1 | The plugin configures a Gradle Task Rule to allow execution of any available Grails scripts as Gradle tasks. Simply 2 | prefix the Grails script name with @grails-@ and execute from Gradle. 3 | 4 | {code} 5 | $ gradle grails-refresh-dependencies 6 | {code} 7 | 8 | {note} 9 | Similar to the behavior of Grails itself, the provided script will be passed as the execution for Grails. If the 10 | requested script is provided via a Grails plugin that is not yet installed, then the execution will fail because plugin 11 | resolution in Grails occurs after validating the script. This can be avoided by executing a @gradle assemble@ so that 12 | Grails compilation & plugin resolution occurs after adding a new Grails plugin to the build dependencies. 13 | {note} -------------------------------------------------------------------------------- /src/docs/guide/usage/test.gdoc: -------------------------------------------------------------------------------- 1 | The Grails Gradle Plugin configures a @test@ task that executes the projects tests through the Grails framework. 2 | Additionally, the plugin configures the normal Gradle @check@ task with a dependency on @test@. 3 | 4 | {code} 5 | $ gradle test 6 | :test 7 | | Loading Grails 2.3.5 8 | ... 9 | | Tests PASSED - view reports in /Users/jengelman/workspace/personal/gg-test/build/test-results 10 | 11 | BUILD SUCCESSFUL 12 | 13 | Total time: 14.181 secs 14 | 15 | $ gradle check 16 | :grails-test-app UP-TO-DATE 17 | :test UP-TO-DATE 18 | :check UP-TO-DATE 19 | 20 | BUILD SUCCESSFUL 21 | 22 | Total time: 1.177 secs 23 | {code} 24 | 25 | The plugin configures test results by default to be output to @build/test-results@ 26 | 27 | h4. Running Specific Test Phases 28 | 29 | The @GrailsTestTask@ allows for configuring the specific test phases through the @phases@ property. By default the 30 | @test@ task is configured with no phases which results in Grails executing *ALL* test phases. This can be 31 | modified as such: 32 | 33 | {code} 34 | test { 35 | phases = ['unit:', 'integration:'] 36 | } 37 | {code} 38 | 39 | The above block will configure @test@ to only execute the @unit@ and @integration@ test phases. 40 | 41 | {note} 42 | The @phases@ property of @GrailsTestTask@ gets passed to Grails's @test-app@ command directly. Therefore, you must provide 43 | content that is compatible with the @test-app@ script. Grails test phase/type selection is of the form @:@. 44 | Valid syntaxes include (not a complete list): @unit:@, @unit:unit@, @unit:spock@, @:spock@, etc. 45 | 46 | {code} 47 | phases = ['unit:'] //Execute all tests types in the unit phase 48 | phases = ['integration:spock'] //Execute all Spock tests in the integration phase 49 | phases = [':unit'] //Execute all JUnit test type in all phases 50 | {code} 51 | 52 | Refer to the section "Targeting Test Types and/or Phases":http://grails.org/doc/latest/guide/single.html#testing in the 53 | Grails User Guide for additional information. 54 | {note} 55 | 56 | h4. Configuring a Test Task Rule 57 | 58 | It may be beneficial to configure a Gradle task rule to execute specific test phases from the command line. This can 59 | be accomplished as so: 60 | 61 | {code} 62 | project.tasks.addRule('Pattern: test') { String taskName -> 63 | if (taskName.startsWith('test')) { 64 | task(taskName, type: GrailsTestTask) { 65 | String testPhase = (taskName - 'test').toLowerCase() 66 | phases = [testPhase + ':'] 67 | } 68 | } 69 | } 70 | 71 | $ gradle testUnit //Execute the unit test phase 72 | {code} 73 | 74 | {note} 75 | When adding a a TaskRule for Grails tasks, avoid using a prefix that begins with {code}grails-{code}. This is the prefix 76 | that the plugin uses for executing arbitrary Grails scripts. Gradle doesn't provide a method to order TaskRules, so 77 | using this prefix will likely result in a duplicate task exception. 78 | {note} 79 | 80 | h4. Running Specific Tests 81 | 82 | In matching with the Gradle standard, use the @-Dtest.single@ property to defined single tests to run. The @GrailsTestTask@ 83 | observes this system property and will pass the value as is to the Grails test task. 84 | 85 | {code} 86 | $ gradle test -Dtest.single=FooController 87 | {code} 88 | 89 | {note} 90 | The @--test@ syntax introduced in Gradle 1.10 is not supported for selecting tests to execute. This is because the plugin 91 | is delegating to the underlying @GrailsLauncher@ to execute tests and not using Gradle's @Test@ class as a base. All the 92 | normal test selection methods for the Grails "@test-app@":http://grails.org/doc/latest/ref/Command%20Line/test-app.html 93 | command are supported since the value of @test.single@ is passed directly as a command line argument to the Grails script. 94 | 95 | {code} 96 | $ gradle test -Dtest.single="Foo Bar" 97 | {code} 98 | {note} 99 | 100 | h4. Setting the Test Results Output Directly 101 | 102 | If multiple @GrailsTestTasks@ are configured in a project and are part of the normal build process, it may be benefical 103 | to configure each task to output its test results to a different directory. By default, Grails cleans the test output 104 | directory before running tests so that the test report matches the tests executed. Use the @testResultsDir@ property on 105 | @GrailsTestTask@ to configure the test output directory. 106 | 107 | {code} 108 | task unit(type: GrailsTestTask) { 109 | testResultsDir = file('build/reports/test-unit') 110 | phases = ['unit:'] 111 | } 112 | 113 | task integration(type: GrailsTestTask) { 114 | testResultsDir = file('build/reports/test-int') 115 | phases = ['integration:'] 116 | } 117 | 118 | test.enabled = false // Disable the default test task that executes all phases 119 | check.dependsOn [unit, integration] // Configure test phase tasks to execute on the 'check' task 120 | {code} -------------------------------------------------------------------------------- /src/docs/guide/usage/upgrade.gdoc: -------------------------------------------------------------------------------- 1 | Grails ships with an @upgrade@ that is used to upgrade an application or plugin from one version of Grails 2 | to another. Use of this command is *NOT* supported via the Grails-Gradle plugin. This script requires an actual 3 | Grails installation on the machine. 4 | 5 | Instead, the plugin will automatically modify the @application.properties@ to reflect both the version of 6 | Grails and the application's version (as specific by @grails.grailsVersion@ and @project.version@ 7 | respectively). This synchronization will occur as the during any @GrailsTask@. 8 | 9 | {note} 10 | This behavior is identical to the behavior of Maven enabled Grails packages as stated in 11 | "MAVEN-137":http://jira.grails.org/browse/MAVEN-137 12 | {note} 13 | 14 | {warning} 15 | The Grails version synchronization will allow you to change the Grails version via the @build.gradle@ file, however, it 16 | will *NOT* apply any upgrades that maybe be obtained through a normal @grails upgrade@ process. It is the responsibility 17 | of the user to manually apply any differences that may occur. 18 | 19 | A good resource for this is the "What's new in Grails x.y":http://grails.org/doc/latest/guide/introduction.html. 20 | 21 | Alternatively, you can initialize a new project with the new Grails version and compare the 2 directories with your 22 | favorite diff tool. 23 | {warning} -------------------------------------------------------------------------------- /src/docs/ref/Task Rules/grails-.gdoc: -------------------------------------------------------------------------------- 1 | h1. grails- 2 | 3 | h2. Purpose 4 | 5 | Allows execution of arbitrary Grails scripts from the Gradle command line. 6 | 7 | h3. Description 8 | 9 | {code} 10 | $ gradle grails-refresh-dependencies 11 | {code} 12 | 13 | Pass arguments to Grails scripts 14 | 15 | {code} 16 | $ gradle grails-create-controller -PgrailsArgs="FooController" 17 | {code} 18 | 19 | Set environment for Grails script 20 | 21 | {code} 22 | $ gradle grails-run-app -PgrailsEnv=production 23 | {code} -------------------------------------------------------------------------------- /src/docs/ref/Tasks/init-plugin.gdoc: -------------------------------------------------------------------------------- 1 | h1. init-plugin 2 | 3 | h2. Purpose 4 | 5 | Initializes a new Grails plugin project in the current working directory. 6 | 7 | h3. Description 8 | 9 | Calls to the @create-plugin@ Grails script and passes the @version@ property. -------------------------------------------------------------------------------- /src/docs/ref/Tasks/init.gdoc: -------------------------------------------------------------------------------- 1 | h1. init 2 | 3 | h2. Purpose 4 | 5 | Initialize a new Grails application project in the current directory. 6 | 7 | h3. Description 8 | 9 | Calls to the @create-app@ Grails script and passes the @version@ property. -------------------------------------------------------------------------------- /src/docs/ref/Tasks/packagePlugin.gdoc: -------------------------------------------------------------------------------- 1 | h1. packagePlugin 2 | 3 | h2. Purpose 4 | 5 | Packages a Grails plugin project as a source ZIP file by default. 6 | 7 | h3. Description 8 | 9 | Calls to the @package-plugin@ Grails script. 10 | Configures the output artifact for the runtime and default Gradle configurations to the be the resulting ZIP file. -------------------------------------------------------------------------------- /src/docs/ref/Tasks/run.gdoc: -------------------------------------------------------------------------------- 1 | h1. run 2 | 3 | h2. Purpose 4 | 5 | Start a Grails application using an embedded container. 6 | 7 | h3. Description 8 | 9 | Calls to the @run-app@ Grails script. By default executes in the @development@ environment. By default enables 10 | class-reloading via Spring Loaded if it is available on the classpath. -------------------------------------------------------------------------------- /src/docs/ref/Tasks/test.gdoc: -------------------------------------------------------------------------------- 1 | h1. test 2 | 3 | h2. Purpose 4 | 5 | Executes the Grails tests via the built in test runner in Grails. 6 | 7 | h3. Description 8 | 9 | Calls the @test-app@ Grails script. By default passes no arguments, which results in all test phases and types 10 | being executed. 11 | 12 | Select specific tests to execute: 13 | 14 | {code} 15 | $ gradle test -Dtest.single="Foo" 16 | {code} 17 | 18 | Value of @test.single@ is passed as a Grails argument which utilizes Grails's pattern matching for which tests will 19 | be executed. -------------------------------------------------------------------------------- /src/docs/ref/Tasks/war.gdoc: -------------------------------------------------------------------------------- 1 | h1. war 2 | 3 | h2. Purpose 4 | 5 | Build an application WAR file. 6 | 7 | h3. Description 8 | 9 | Calls the @war@ Grails script. By default sets the environment to @production@. 10 | Configures the output artifact for the runtime and default Gradle configurations to the be the resulting WAR file. -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/GrailsPlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin 18 | 19 | import org.gradle.api.InvalidUserDataException 20 | import org.gradle.api.Plugin 21 | import org.gradle.api.Project 22 | import org.gradle.api.artifacts.Configuration 23 | import org.gradle.api.artifacts.ConfigurationContainer 24 | import org.gradle.api.artifacts.DependencyResolveDetails 25 | import org.gradle.api.internal.ConventionMapping 26 | import org.gradle.api.internal.file.FileResolver 27 | import org.gradle.api.plugins.BasePlugin 28 | import org.gradle.api.plugins.GroovyBasePlugin 29 | import org.gradle.internal.reflect.Instantiator 30 | import org.grails.gradle.plugin.dependencies.DependencyConfigurer 31 | import org.grails.gradle.plugin.dependencies.DependencyConfigurerFactory 32 | import org.grails.gradle.plugin.eclipse.GrailsEclipseConfigurator 33 | import org.grails.gradle.plugin.idea.GrailsIdeaConfigurator 34 | import org.grails.gradle.plugin.internal.DefaultGrailsProject 35 | import org.grails.gradle.plugin.tasks.GrailsTask 36 | import org.grails.gradle.plugin.tasks.GrailsTaskConfigurator 37 | 38 | import javax.inject.Inject 39 | 40 | class GrailsPlugin implements Plugin { 41 | 42 | private final Instantiator instantiator 43 | private final FileResolver fileResolver 44 | 45 | @Inject 46 | GrailsPlugin(Instantiator instantiator, FileResolver fileResolver) { 47 | this.instantiator = instantiator 48 | this.fileResolver = fileResolver 49 | } 50 | 51 | void apply(Project project) { 52 | project.plugins.apply(BasePlugin) 53 | project.plugins.apply(GroovyBasePlugin) 54 | 55 | DefaultGrailsProject grailsProject = project.extensions.create('grails', DefaultGrailsProject, project) 56 | project.convention.plugins.put('grails', grailsProject) 57 | 58 | grailsProject.conventionMapping.with { 59 | map("projectDir") { project.projectDir } 60 | map("projectWorkDir") { project.buildDir } 61 | } 62 | 63 | Configuration bootstrapConfiguration = getOrCreateConfiguration(project, "bootstrap") 64 | 65 | Configuration compileConfiguration = getOrCreateConfiguration(project, "compile") 66 | Configuration providedConfiguration = getOrCreateConfiguration(project, "provided") 67 | Configuration runtimeConfiguration = getOrCreateConfiguration(project, "runtime") 68 | Configuration testConfiguration = getOrCreateConfiguration(project, "test") 69 | Configuration resourcesConfiguration = getOrCreateConfiguration(project, "resources") 70 | Configuration springloadedConfiguration = getOrCreateConfiguration(project, "springloaded") 71 | 72 | runtimeConfiguration.extendsFrom(compileConfiguration) 73 | testConfiguration.extendsFrom(runtimeConfiguration) 74 | 75 | grailsProject.onSetGrailsVersion { String grailsVersion -> 76 | DependencyConfigurer dependenciesUtil = DependencyConfigurerFactory.build(project, grailsProject) 77 | dependenciesUtil.configureBootstrapClasspath(bootstrapConfiguration) 78 | dependenciesUtil.configureProvidedClasspath(providedConfiguration) 79 | dependenciesUtil.configureCompileClasspath(compileConfiguration) 80 | dependenciesUtil.configureRuntimeClasspath(runtimeConfiguration) 81 | dependenciesUtil.configureTestClasspath(testConfiguration) 82 | dependenciesUtil.configureResources(resourcesConfiguration) 83 | } 84 | grailsProject.onSetGroovyVersion { String groovyVersion -> 85 | DependencyConfigurer dependenciesUtil = DependencyConfigurerFactory.build(project, grailsProject) 86 | dependenciesUtil.configureGroovyBootstrapClasspath(bootstrapConfiguration) 87 | dependenciesUtil.configureGroovyCompileClasspath(compileConfiguration) 88 | 89 | project.configurations.all { Configuration config -> 90 | config.resolutionStrategy { 91 | eachDependency { DependencyResolveDetails details -> 92 | if (details.requested.group == 'org.codehaus.groovy') { 93 | if (details.requested.name == 'groovy-all') { 94 | details.useVersion groovyVersion 95 | } 96 | if (details.requested.name == 'groovy') { 97 | details.useTarget group: details.requested.group, name: 'groovy-all', version: groovyVersion 98 | } 99 | } 100 | } 101 | } 102 | } 103 | } 104 | 105 | configureSourceSets(project, grailsProject) 106 | configureTasks(project, grailsProject) 107 | project.tasks.withType(GrailsTask) { GrailsTask task -> 108 | ConventionMapping conventionMapping = task.conventionMapping 109 | conventionMapping.with { 110 | map("projectDir") { grailsProject.projectDir } 111 | map("projectWorkDir") { grailsProject.projectWorkDir } 112 | map("grailsVersion") { grailsProject.grailsVersion } 113 | map("pluginProject") { grailsProject.pluginProject } 114 | 115 | map("bootstrapClasspath") { bootstrapConfiguration } 116 | 117 | map("providedClasspath") { providedConfiguration } 118 | map("compileClasspath") { compileConfiguration } 119 | map("runtimeClasspath") { runtimeConfiguration } 120 | map("testClasspath") { testConfiguration } 121 | map("sourceSets") { project.sourceSets } 122 | 123 | map("springloaded") { 124 | if (springloadedConfiguration.dependencies.empty) { 125 | DependencyConfigurer dependenciesUtil = DependencyConfigurerFactory.build(project, grailsProject) 126 | dependenciesUtil.configureSpringloaded(springloadedConfiguration) 127 | } 128 | 129 | def lenient = springloadedConfiguration.resolvedConfiguration.lenientConfiguration 130 | if (lenient.unresolvedModuleDependencies) { 131 | def springloadedDependency = springloadedConfiguration.dependencies.toList().first() 132 | project.logger.warn("Failed to resolve springloaded dependency: $springloadedDependency (reloading will be disabled)") 133 | null 134 | } else { 135 | springloadedConfiguration 136 | } 137 | } 138 | } 139 | 140 | doFirst { 141 | if (grailsProject.grailsVersion == null) { 142 | throw new InvalidUserDataException("You must set 'grails.grailsVersion' property before Grails tasks can be run") 143 | } 144 | } 145 | } 146 | configureIdea(project) 147 | configureEclipse(project) 148 | } 149 | 150 | void configureTasks(Project project, GrailsProject grailsProject) { 151 | new GrailsTaskConfigurator().configure(project, grailsProject) 152 | } 153 | 154 | void configureSourceSets(Project project, GrailsProject grailsProject) { 155 | new GrailsSourceSetConfigurator(instantiator, fileResolver).configure(project, grailsProject) 156 | } 157 | 158 | void configureIdea(Project project) { 159 | new GrailsIdeaConfigurator().configure(project) 160 | } 161 | 162 | void configureEclipse(Project project) { 163 | new GrailsEclipseConfigurator().configure(project) 164 | } 165 | 166 | Configuration getOrCreateConfiguration(Project project, String name) { 167 | ConfigurationContainer container = project.configurations 168 | container.findByName(name) ?: container.create(name) 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/GrailsProject.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License") 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin 18 | 19 | interface GrailsProject { 20 | 21 | void setGrailsVersion(String grailsVersion) 22 | 23 | String getGrailsVersion() 24 | 25 | String getSpringLoadedVersion() 26 | 27 | void setSpringLoadedVersion(String springLoadedVersion) 28 | 29 | boolean isPluginProject() 30 | 31 | File getPluginDescriptor() 32 | 33 | File getProjectWorkDir() 34 | 35 | File getProjectDir() 36 | 37 | String getGroovyVersion() 38 | 39 | void setGroovyVersion(String groovyVersion) 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/GrailsSourceSetConfigurator.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.internal.file.FileResolver 5 | import org.gradle.internal.reflect.Instantiator 6 | 7 | /** 8 | * Configures the source sets with the Grails source structure. Much of this code is replicated from the Java and 9 | * Groovy plugins. 10 | */ 11 | class GrailsSourceSetConfigurator { 12 | 13 | private final Instantiator instantiator 14 | private final FileResolver fileResolver 15 | 16 | GrailsSourceSetConfigurator(Instantiator instantiator, FileResolver fileResolver) { 17 | this.instantiator = instantiator 18 | this.fileResolver = fileResolver 19 | } 20 | 21 | void configure(Project project, GrailsProject grailsProject) { 22 | 23 | //Add the 'groovy' DSL extension to the source sets 24 | 25 | createMainSourceSet(project, grailsProject) 26 | createTestSourceSet(project, grailsProject) 27 | } 28 | 29 | /** 30 | * Configure the main source sets 31 | */ 32 | void createMainSourceSet(Project project, GrailsProject grailsProject) { 33 | def sourceSetClosure = { 34 | main { 35 | groovy { 36 | srcDirs = [ 37 | 'grails-app/conf', 38 | 'grails-app/controllers', 39 | 'grails-app/domain', 40 | 'grails-app/services', 41 | 'grails-app/taglib', 42 | 'grails-app/utils', 43 | 'src/groovy', 44 | 'scripts' 45 | ] 46 | filter { 47 | exclude 'grails-app/conf/hibernate' 48 | exclude 'grails-app/conf/spring' 49 | } 50 | } 51 | resources { 52 | srcDirs = [ 53 | 'grails-app/conf/hibernate', 54 | 'grails-app/conf/spring', 55 | 'grails-app/views', 56 | 'web-app' 57 | ] 58 | } 59 | java { 60 | srcDirs = [ 61 | 'src/java' 62 | ] 63 | } 64 | output.with { 65 | classesDir = buildPath(grailsProject, 'classes') 66 | ['plugin-build-classes', 'plugin-classes', 'plugin-provided-classes'].each { 67 | dir buildPath(grailsProject, it) 68 | } 69 | dir 'buildPlugins' 70 | resourcesDir = buildPath(grailsProject, 'resources') 71 | } 72 | } 73 | } 74 | 75 | project.sourceSets(sourceSetClosure) 76 | } 77 | 78 | String buildPath(GrailsProject project, String path) { 79 | return new File(project.projectWorkDir, path).path 80 | } 81 | 82 | /** 83 | * Configure the test source set 84 | */ 85 | void createTestSourceSet(Project project, GrailsProject grailsProject) { 86 | def sourceSetClosure = { 87 | test { 88 | groovy { 89 | srcDirs = [ 90 | 'test/functional', 91 | 'test/integration', 92 | 'test/unit' 93 | ] 94 | } 95 | output.with { 96 | classesDir = buildPath(grailsProject, 'test-classes') 97 | } 98 | } 99 | } 100 | 101 | project.sourceSets(sourceSetClosure) 102 | } 103 | } -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/dependencies/DependencyConfigurer.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.dependencies 2 | 3 | import groovy.transform.TupleConstructor 4 | import org.gradle.api.Project 5 | import org.gradle.api.artifacts.Configuration 6 | import org.gradle.api.artifacts.ModuleDependency 7 | import org.grails.gradle.plugin.GrailsProject 8 | import org.grails.launcher.version.GrailsVersion 9 | import org.grails.launcher.version.GrailsVersionQuirks 10 | 11 | /** 12 | * Abstract class for the dependency configuration. 13 | */ 14 | @TupleConstructor 15 | abstract class DependencyConfigurer { 16 | 17 | protected final Project project 18 | protected final GrailsProject grailsProject 19 | protected final GrailsVersion grailsVersion 20 | protected final GrailsVersionQuirks grailsVersionQuirks 21 | 22 | DependencyConfigurer(Project project, GrailsProject grailsProject, GrailsVersion grailsVersion) { 23 | this.project = project 24 | this.grailsProject = grailsProject 25 | this.grailsVersion = grailsVersion 26 | this.grailsVersionQuirks = new GrailsVersionQuirks(grailsVersion) 27 | } 28 | 29 | abstract void configureBootstrapClasspath(Configuration configuration) 30 | 31 | abstract void configureGroovyBootstrapClasspath(Configuration configuration) 32 | 33 | abstract void configureProvidedClasspath(Configuration configuration) 34 | 35 | abstract void configureCompileClasspath(Configuration configuration) 36 | 37 | abstract void configureGroovyCompileClasspath(Configuration configuration) 38 | 39 | abstract void configureRuntimeClasspath(Configuration configuration) 40 | 41 | abstract void configureTestClasspath(Configuration configuration) 42 | 43 | abstract void configureResources(Configuration configuration) 44 | 45 | abstract void configureSpringloaded(Configuration configuration) 46 | 47 | protected ModuleDependency addDependency(String notation, Configuration configuration) { 48 | ModuleDependency dependency = project.dependencies.create(notation) as ModuleDependency 49 | configuration.dependencies.add(dependency) 50 | dependency 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/dependencies/DependencyConfigurerFactory.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.dependencies 2 | 3 | import org.gradle.api.Project 4 | import org.grails.gradle.plugin.GrailsProject 5 | import org.grails.launcher.version.GrailsVersion 6 | 7 | /** 8 | * Creates the proper dependency configuration instance for this Grails version. 9 | * Currently all project use the same configuration, but future version may require 10 | * more substantial customization. 11 | */ 12 | class DependencyConfigurerFactory { 13 | 14 | static DependencyConfigurer build(Project project, GrailsProject grailsProject) { 15 | GrailsVersion version = GrailsVersion.parse(grailsProject.grailsVersion) 16 | return new GrailsDependenciesConfigurer(project, grailsProject, version) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/dependencies/GrailsDependenciesConfigurer.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.dependencies 18 | 19 | import groovy.transform.InheritConstructors 20 | import org.gradle.api.artifacts.Configuration 21 | 22 | /** 23 | * Default Grails dependency configuration 24 | */ 25 | @InheritConstructors 26 | class GrailsDependenciesConfigurer extends DependencyConfigurer { 27 | 28 | void configureBootstrapClasspath(Configuration configuration) { 29 | ["bootstrap", "scripts", "resources"].each { 30 | addDependency("org.grails:grails-$it:${grailsVersion}", configuration).exclude(group: "org.slf4j") 31 | } 32 | 33 | if (grailsVersion.is(1)) { 34 | addDependency("org.apache.ant:ant:1.8.2", configuration) 35 | } 36 | 37 | if (grailsVersionQuirks.isRequiresExplicitIvyDependency()) { 38 | addDependency("org.apache.ivy:ivy:2.1.0", configuration) 39 | } 40 | 41 | if (grailsVersionQuirks.isRequiresExplicitLoggingBootstrapDependencies()) { 42 | addDependency("org.slf4j:jcl-over-slf4j:1.6.2", configuration); 43 | addDependency("log4j:log4j:1.2.17", configuration); 44 | } 45 | } 46 | 47 | void configureGroovyBootstrapClasspath(Configuration configuration) { 48 | addGroovyDependency(configuration) 49 | } 50 | 51 | void configureProvidedClasspath(Configuration configuration) { 52 | 53 | } 54 | 55 | void configureCompileClasspath(Configuration configuration) { 56 | if (grailsVersionQuirks.isHasGrailsDependenciesPom()) { 57 | addDependency("org.grails:grails-dependencies:${grailsVersion}", configuration) 58 | } 59 | } 60 | 61 | void configureGroovyCompileClasspath(Configuration configuration) { 62 | addGroovyDependency(configuration) 63 | } 64 | 65 | void configureRuntimeClasspath(Configuration configuration) { 66 | if (grailsVersion.is(2) && grailsVersion.minor >= 3) { 67 | addDependency('com.h2database:h2:1.3.170', configuration) 68 | } 69 | } 70 | 71 | void configureTestClasspath(Configuration configuration) { 72 | addDependency("org.grails:grails-plugin-testing:${grailsVersion}", configuration) 73 | addDependency("org.grails:grails-test:${grailsVersion}", configuration) 74 | if (grailsVersion.is(2, 4)) { 75 | addDependency('junit:junit:4.11', configuration) 76 | addDependency('org.spockframework:spock-core:0.7-groovy-2.0', configuration) 77 | } 78 | } 79 | 80 | void configureResources(Configuration configuration) { 81 | addDependency("org.grails:grails-resources:$grailsVersion", configuration).transitive = false 82 | } 83 | 84 | void configureSpringloaded(Configuration configuration) { 85 | String version = grailsProject.springLoadedVersion 86 | if (version >= '1.1.5' && !version.endsWith('.RELEASE')) { 87 | version += '.RELEASE' 88 | } 89 | if (version.endsWith('.RELEASE')) { 90 | addDependency("org.springframework:springloaded:$version", configuration) 91 | } else { 92 | addDependency("org.springsource.springloaded:springloaded-core:$version", configuration) 93 | } 94 | } 95 | 96 | private addGroovyDependency(Configuration configuration) { 97 | addDependency("org.codehaus.groovy:groovy-all:${grailsProject.groovyVersion}", configuration) 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/eclipse/GrailsEclipseConfigurator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.eclipse 18 | 19 | import org.gradle.api.Project 20 | import org.gradle.api.artifacts.Configuration 21 | import org.gradle.api.artifacts.ProjectDependency 22 | import org.gradle.api.plugins.BasePlugin 23 | import org.gradle.api.tasks.Delete 24 | import org.gradle.plugins.ide.eclipse.EclipsePlugin 25 | import org.gradle.plugins.ide.eclipse.model.EclipseModel 26 | import org.grails.gradle.plugin.tasks.GrailsEclipseJdtGroovyTask 27 | 28 | /** 29 | * Configure the Eclipse IDE integration for the project. 30 | * 31 | * Created by Jeevanandam M. (jeeva@myjeeva.com) on 7/4/14. 32 | */ 33 | class GrailsEclipseConfigurator { 34 | static final GRADLE_GRAILS_PLUGIN_DIR_LINK_NAME = '.link_to_grails_plugins' 35 | static final GRADLE_GRAILS_PLUGIN_RELATIVE_DIR = 'buildPlugins' 36 | static final GRADLE_GRAILS_OUTPUT_RELATIVE_DIR = 'target-eclipse/classes' 37 | static final ECLIPSE_CLASS_PATH_ENTRY_NODE_NAME = 'classpathentry' 38 | 39 | /** 40 | * Registering Eclipse IDE project configuration 41 | * 42 | * @param project gradle project instance of {@code Project} 43 | */ 44 | void configure(Project project) { 45 | project.plugins.withType(EclipsePlugin) { 46 | project.eclipse { 47 | def model = project.extensions.getByType(EclipseModel.class) 48 | createEclipseProject(project, model) 49 | createEclipseClasspath(project, model) 50 | } 51 | 52 | configureTasksAndHooks(project) 53 | } 54 | } 55 | 56 | private void createEclipseProject(Project project, EclipseModel model) { 57 | String pluginLinkLocation = "${project.projectDir.absolutePath}${File.separator}${GRADLE_GRAILS_PLUGIN_RELATIVE_DIR}" 58 | 59 | model.project { 60 | buildCommands.clear() 61 | buildCommand 'org.eclipse.wst.common.project.facet.core.builder' 62 | buildCommand 'org.eclipse.jdt.core.javabuilder' 63 | 64 | natures = ['org.grails.ide.eclipse.core.nature', 65 | 'org.eclipse.jdt.groovy.core.groovyNature', 66 | 'org.eclipse.jdt.core.javanature', 67 | 'org.eclipse.wst.common.project.facet.core.nature'] 68 | 69 | linkedResource name: GRADLE_GRAILS_PLUGIN_DIR_LINK_NAME, 70 | type: '2', 71 | location: pluginLinkLocation 72 | 73 | file.withXml { 74 | def node = it.asNode() 75 | 76 | /* 77 | * Project filters for build, .gradle, target 78 | */ 79 | Node filteredResources = new XmlParser().parseText(""" 80 | 81 | 1407523962826 82 | 83 | 10 84 | 85 | org.eclipse.ui.ide.multiFilter 86 | 1.0-name-matches-false-false-target 87 | 88 | 89 | 90 | 1407523962836 91 | 92 | 10 93 | 94 | org.eclipse.ui.ide.multiFilter 95 | 1.0-name-matches-false-false-build 96 | 97 | 98 | 99 | 1407529877923 100 | 101 | 10 102 | 103 | org.eclipse.ui.ide.multiFilter 104 | 1.0-name-matches-false-false-.gradle 105 | 106 | 107 | 108 | 1407529877926 109 | 110 | 10 111 | 112 | org.eclipse.ui.ide.multiFilter 113 | 1.0-name-matches-false-false-buildPlugins 114 | 115 | 116 | """) 117 | 118 | node.append(filteredResources) 119 | } 120 | } 121 | } 122 | 123 | private void createEclipseClasspath(Project project, EclipseModel model) { 124 | model.classpath { 125 | defaultOutputDir = new File(GRADLE_GRAILS_OUTPUT_RELATIVE_DIR) 126 | 127 | containers.clear() 128 | 129 | def configurations = project.configurations 130 | plusConfigurations += [configurations.bootstrap] 131 | plusConfigurations += [configurations.runtime] 132 | plusConfigurations += [configurations.test] 133 | 134 | file.withXml { 135 | def node = it.asNode() 136 | 137 | // Excluding resources source directories 138 | handleResourceSourceDirs(node) 139 | 140 | // Adding Plugin source directories 141 | handlePluginSourceDirs(project, node) 142 | 143 | // Containers 144 | node.appendNode ECLIPSE_CLASS_PATH_ENTRY_NODE_NAME, [kind: 'con', path: 'org.eclipse.jdt.launching.JRE_CONTAINER'] 145 | node.appendNode ECLIPSE_CLASS_PATH_ENTRY_NODE_NAME, [kind: 'con', path: 'GROOVY_DSL_SUPPORT'] 146 | } 147 | } 148 | } 149 | 150 | private void configureTasksAndHooks(Project project) { 151 | // cleanEclipseJdtGroovy task 152 | project.tasks.create(GrailsEclipseJdtGroovyTask.ECLIPSE_JDT_GROOVY_CLEAN_TASK_NAME, Delete.class).with { 153 | description = 'Cleans the Eclipse JDT Groovy settings file.' 154 | delete GrailsEclipseJdtGroovyTask.ECLIPSE_GROOVY_JDT_PREFS_FILE 155 | } 156 | project.tasks.findByName('cleanEclipse')?.dependsOn(GrailsEclipseJdtGroovyTask.ECLIPSE_JDT_GROOVY_CLEAN_TASK_NAME) 157 | 158 | // eclipseJdtGroovy task 159 | project.task(GrailsEclipseJdtGroovyTask.ECLIPSE_JDT_GROOVY_TASK_NAME, type: GrailsEclipseJdtGroovyTask) 160 | 161 | // eclipseClasspath depends on assemble to resolve plugins 162 | project.tasks.findByName('eclipseClasspath')?.dependsOn(BasePlugin.ASSEMBLE_TASK_NAME) 163 | } 164 | 165 | private void handleResourceSourceDirs(Node node) { 166 | ['grails-app/conf', 'grails-app/conf/hibernate', 'grails-app/conf/spring', 167 | 'grails-app/views', 'web-app'].collect { dirPath -> 168 | def removeNode = node.'**'.find { 169 | it.@path == dirPath 170 | } 171 | 172 | if (removeNode) { 173 | node.remove(removeNode) 174 | } 175 | } 176 | node.appendNode(ECLIPSE_CLASS_PATH_ENTRY_NODE_NAME, [kind: 'src', path: 'grails-app/conf', excluding: 'spring/|hibernate/']) 177 | } 178 | 179 | private void handlePluginSourceDirs(Project project, Node node) { 180 | // Cleanup .zip from lib kind in the classpathentry 181 | node.'**'.findAll { 182 | it.@path?.toLowerCase()?.endsWith('.zip') 183 | }?.each { 184 | node.remove(it) 185 | } 186 | 187 | pluginSourceDirs(project).each { path -> 188 | def nodeValues = [kind: 'src', path: path] 189 | if (path.endsWith('grails-app/conf')) { 190 | nodeValues << [excluding: 'BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy'] 191 | } 192 | 193 | node.appendNode(ECLIPSE_CLASS_PATH_ENTRY_NODE_NAME, nodeValues) 194 | .appendNode('attributes') 195 | .appendNode('attribute', [name: 'org.grails.ide.eclipse.core.SOURCE_FOLDER', value: 'true']) 196 | } 197 | } 198 | 199 | /** 200 | * Note: Same hacky approach as GrailsIdeaConfigurator for plugin 201 | * directories processing. It assumes that all plugins have the 'org.grails.plugins' group. 202 | * */ 203 | private pluginSourceDirs(Project project) { 204 | def plugins = [] as Set 205 | 206 | ['bootstrap', 'compile', 'runtime'].each { name -> 207 | Configuration configuration = project.configurations.getByName(name) 208 | if (configuration) { 209 | plugins.addAll(configuration.allDependencies.findAll { 210 | !(it instanceof ProjectDependency) && it.group == 'org.grails.plugins' 211 | }) 212 | } 213 | } 214 | 215 | def pluginPaths = [] 216 | plugins.each { dependency -> 217 | ['src/groovy', 'grails-app/i18n', 'grails-app/controllers', 'grails-app/domain', 218 | 'grails-app/services', 'grails-app/taglib', 'src/java', 'grails-app/conf'].each { relativePath -> 219 | String path = "${File.separator}${dependency.name}-${dependency.version}${File.separator}${relativePath}" 220 | File dir = new File(project.projectDir, "${File.separator}buildPlugins${path}") 221 | if (dir.exists()) { 222 | pluginPaths << "${GRADLE_GRAILS_PLUGIN_DIR_LINK_NAME}${path}" 223 | } 224 | } 225 | } 226 | 227 | pluginPaths 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/idea/GrailsIdeaConfigurator.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.idea 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.XmlProvider 5 | import org.gradle.api.artifacts.Configuration 6 | import org.gradle.api.artifacts.Dependency 7 | import org.gradle.api.artifacts.ProjectDependency 8 | import org.gradle.plugins.ide.idea.IdeaPlugin 9 | import org.gradle.plugins.ide.idea.model.IdeaModule 10 | 11 | /** 12 | * Configure the IDEA integration for the project. 13 | */ 14 | class GrailsIdeaConfigurator { 15 | 16 | void configure(Project project) { 17 | project.plugins.withType(IdeaPlugin) { 18 | project.idea { 19 | def configurations = project.configurations 20 | //Map IDEA scopes to Gradle configurations 21 | module.scopes = [ 22 | PROVIDED: [plus: [configurations.provided], minus: []], 23 | COMPILE: [plus: [configurations.compile], minus: []], 24 | RUNTIME: [plus: [configurations.runtime], minus: [configurations.compile]], 25 | TEST: [plus: [configurations.test], minus: [configurations.runtime]] 26 | ] 27 | //Configure additional source and test directories 28 | sourceDirs(project, module) 29 | testDirs(project, module) 30 | pluginSourceDirs(project, module) 31 | module.conventionMapping.excludeDirs = { excludedBuildFiles(project) } 32 | module.iml.withXml { XmlProvider xmlProvider -> 33 | declareGrailsFacets(project, xmlProvider.asNode()) 34 | } 35 | } 36 | } 37 | } 38 | 39 | private LinkedHashSet excludedBuildFiles(Project project) { 40 | return [project.buildDir, project.file('.gradle')] as LinkedHashSet 41 | } 42 | 43 | /** 44 | * Register the source directories for the project and any plugins with IDEA 45 | */ 46 | private void sourceDirs(Project project, IdeaModule module) { 47 | module.conventionMapping.sourceDirs = { 48 | (project.sourceSets.main.allSource.srcDirs as LinkedHashSet) - 49 | (project.sourceSets.main.resources.srcDirs as LinkedHashSet) 50 | } 51 | } 52 | 53 | /** 54 | * Calculate that plugin source directories. This is required because Gradle treats the plugin zip file 55 | * as a jar, assuming that all the directories contained within are packages. 56 | * 57 | * This is a little hacky in that it assumes that all plugins have the 'org.grails.plugins' group. 58 | * This needs to be made more robust (perhaps a 'pluginCompile' and 'pluginRuntime' configuration) 59 | */ 60 | private void pluginSourceDirs(Project project, IdeaModule module) { 61 | ['bootstrap', 'compile', 'runtime'].each { name -> 62 | registerPluginSourceDirectory(project, project.configurations.getByName(name)) { dir -> 63 | module.sourceDirs += dir 64 | } 65 | } 66 | registerPluginSourceDirectory(project, project.configurations.test) { dir -> 67 | module.testSourceDirs += dir 68 | } 69 | } 70 | 71 | private void registerPluginSourceDirectory(Project project, Configuration configuration, Closure mapping) { 72 | configuration.allDependencies.matching({ dependency -> 73 | isPluginZip(dependency) 74 | }).all { dependency -> 75 | ['src/groovy', 'grails-app/i18n', 'grails-app/controllers', 'grails-app/domain', 76 | 'grails-app/services', 'grails-app/taglib', 'src/java'].collect { root -> 77 | mapping(pluginDir(dependency, project, root)) 78 | } 79 | } 80 | } 81 | 82 | private boolean isPluginZip(Dependency dependency) { 83 | if (!(dependency instanceof ProjectDependency) && 84 | dependency.group == 'org.grails.plugins') { 85 | return true 86 | } 87 | return false 88 | } 89 | 90 | private void testDirs(Project project, IdeaModule module) { 91 | module.conventionMapping.testSourceDirs = { 92 | project.sourceSets.test.allSource.srcDirs as LinkedHashSet 93 | } 94 | } 95 | 96 | private File pluginDir(Dependency dependency, Project project, String root) { 97 | return new File(project.projectDir, '/buildPlugins/' + dependency.name + '-' + dependency.version + '/' + root) 98 | } 99 | 100 | /** 101 | * Tries to mimic the IML creation that IDEA natively does for Grails projects. 102 | * @param project 103 | * @param iml 104 | */ 105 | private void declareGrailsFacets(Project project, Node iml) { 106 | Node facetManager = iml.component.find { it.@name == "FacetManager" } 107 | if (!facetManager) { 108 | facetManager = iml.appendNode("component", [name: "FacetManager"]) 109 | } 110 | declareSpringFacet(facetManager) 111 | declareGrailsWebFacet(facetManager) 112 | declareHibernateFacet(facetManager) 113 | } 114 | 115 | private void declareSpringFacet(Node facetManager) { 116 | Node spring = facetManager.facet.find { it.@type == 'Spring' } 117 | if (!spring) { 118 | spring = facetManager.appendNode('Spring', [type: 'Spring', name: 'Spring']) 119 | } 120 | Node configuration = spring.configuration[0] 121 | if (!configuration) { 122 | configuration = spring.appendNode('configuration') 123 | } 124 | Node fileset = configuration.fileset.find { it.@id == 'Grails' } 125 | if (!fileset) { 126 | fileset = configuration.appendNode('fileset', [id: 'Grails', name: 'Grails', removed: 'false']) 127 | } 128 | ['web-app/WEB-INF/applicationContext.xml', 'grails-app/conf/spring/resources.xml'].each { file -> 129 | Node fileNode = fileset.file.find { it.text().endsWith(file) } 130 | if (!fileNode) { 131 | fileset.appendNode('file', "file://\$MODULE_DIR\$/${file}") 132 | } 133 | } 134 | } 135 | 136 | private void declareGrailsWebFacet(Node facetManager) { 137 | Node grailsWeb = facetManager.facet.find { it.@type == "web" } 138 | if (!grailsWeb) { 139 | grailsWeb = facetManager.appendNode("facet", [type: "web", name: "GrailsWeb"]) 140 | } 141 | Node configuration = grailsWeb.configuration[0] 142 | if (!configuration) { 143 | configuration = grailsWeb.appendNode("configuration") 144 | } 145 | Node webroots = configuration.webroots[0] 146 | if (!webroots) { 147 | webroots = configuration.appendNode('webroots') 148 | } 149 | ['grails-app/views', 'web-app'].each { root -> 150 | Node rootNode = webroots.root.find { it.@url.endsWith(root) } 151 | if (!rootNode) { 152 | webroots.appendNode('root', [url: "file://\$MODULE_DIR\$/${root}", relative: '/']) 153 | } 154 | } 155 | Node sourceRoots = configuration.sourceRoots[0] 156 | if (!sourceRoots) { 157 | configuration.appendNode('sourceRoots') 158 | } 159 | } 160 | 161 | private void declareHibernateFacet(Node facetManager) { 162 | Node hibernate = facetManager.facet.find { it.@type == 'hibernate' } 163 | if (!hibernate) { 164 | hibernate = facetManager.appendNode('hibernate', [type: 'hibernate', name: 'Hibernate']) 165 | } 166 | Node configuration = hibernate.configuration[0] 167 | if (!configuration) { 168 | configuration = hibernate.appendNode('configuration') 169 | } 170 | Node datasourceMap = configuration.get('datasource-map')[0] 171 | if (!datasourceMap) { 172 | configuration.appendNode('datasource-map') 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/internal/DefaultGrailsProject.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License") 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.internal 18 | 19 | import org.gradle.api.Action 20 | import org.gradle.api.InvalidUserDataException 21 | import org.gradle.api.Project 22 | import org.gradle.api.artifacts.repositories.MavenArtifactRepository 23 | import org.gradle.api.internal.project.ProjectInternal 24 | import org.gradle.listener.ActionBroadcast 25 | import org.grails.gradle.plugin.GrailsProject 26 | 27 | /** 28 | * This is the 'grails' extension object for the Gradle DSL. 29 | */ 30 | public class DefaultGrailsProject implements GrailsProject { 31 | 32 | public static final String DEFAULT_SPRINGLOADED = "1.1.3" 33 | 34 | private final Project project 35 | 36 | private Object projectDir 37 | private Object projectWorkDir 38 | 39 | private String grailsVersion 40 | private String groovyVersion 41 | private String springLoadedVersion = DEFAULT_SPRINGLOADED 42 | 43 | private ActionBroadcast onSetGrailsVersion = new ActionBroadcast() 44 | private ActionBroadcast onSetGroovyVersion = new ActionBroadcast() 45 | 46 | public DefaultGrailsProject(ProjectInternal project) { 47 | this.project = project 48 | } 49 | 50 | public File getProjectDir() { 51 | return projectDir == null ? null : project.file(projectDir) 52 | } 53 | 54 | public File getProjectWorkDir() { 55 | return projectWorkDir == null ? null : project.file(projectWorkDir) 56 | } 57 | 58 | @Override 59 | //Set the Grails version and execute the configuration callback that configures the Grails dependencies 60 | //on the project 61 | public void setGrailsVersion(String grailsVersion) { 62 | if (this.grailsVersion != null) { 63 | throw new InvalidUserDataException("The 'grailsVersion' property can only be set once") 64 | } 65 | this.grailsVersion = grailsVersion 66 | onSetGrailsVersion.execute(grailsVersion) 67 | } 68 | 69 | //Set the Groovy version and execute the configuration callback the configures the Groovy resolution 70 | //strategy on the project 71 | public void setGroovyVersion(String groovyVersion) { 72 | if (this.groovyVersion != null) { 73 | throw new InvalidUserDataException("The 'groovyVersion' property can only be set once") 74 | } 75 | this.groovyVersion = groovyVersion 76 | onSetGroovyVersion.execute(groovyVersion) 77 | } 78 | 79 | public void onSetGrailsVersion(Action action) { 80 | onSetGrailsVersion.add(action) 81 | } 82 | 83 | public void onSetGroovyVersion(Action action) { 84 | onSetGroovyVersion.add(action) 85 | } 86 | 87 | @Override 88 | public String getGrailsVersion() { 89 | return this.grailsVersion 90 | } 91 | 92 | public String getGroovyVersion() { 93 | return this.groovyVersion 94 | } 95 | 96 | @Override 97 | public String getSpringLoadedVersion() { 98 | return springLoadedVersion 99 | } 100 | 101 | @Override 102 | public void setSpringLoadedVersion(String springLoadedVersion) { 103 | this.springLoadedVersion = springLoadedVersion 104 | } 105 | 106 | public boolean isPluginProject() { 107 | return getPluginDescriptor() as boolean 108 | } 109 | 110 | public File getPluginDescriptor() { 111 | getProjectDir().listFiles().find { it.name.endsWith('GrailsPlugin.groovy') } 112 | } 113 | 114 | /** 115 | * Configures the Grails central repositories on the project: 116 | * repositories { 117 | * grails.central() 118 | * } 119 | * 120 | */ 121 | public MavenArtifactRepository central() { 122 | project.repositories.maven { MavenArtifactRepository repository -> 123 | repository.url = 'http://repo.grails.org/grails/repo' 124 | repository.name = 'Grails Central' 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/internal/GrailsLaunchConfigureAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.internal; 18 | 19 | import org.gradle.api.Action; 20 | import org.gradle.api.logging.Logger; 21 | import org.gradle.process.JavaExecSpec; 22 | import org.grails.launcher.ForkedGrailsLauncher; 23 | import org.grails.launcher.Main; 24 | import org.grails.launcher.context.GrailsLaunchContext; 25 | 26 | import java.io.*; 27 | import java.net.MalformedURLException; 28 | import java.net.URL; 29 | import java.net.URLClassLoader; 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | public class GrailsLaunchConfigureAction implements Action { 34 | 35 | private final GrailsLaunchContext launchContext; 36 | private final File springloadedJar; 37 | private final File contextDestination; 38 | 39 | public GrailsLaunchConfigureAction(GrailsLaunchContext launchContext, File springloadedJar, File contextDestination) { 40 | this.launchContext = launchContext; 41 | this.springloadedJar = springloadedJar; 42 | this.contextDestination = contextDestination; 43 | } 44 | 45 | @Override 46 | public void execute(JavaExecSpec javaExec) { 47 | configureReloadAgent(javaExec); // mutates the launch context 48 | 49 | OutputStream fileOut = null; 50 | ObjectOutputStream oos = null; 51 | try { 52 | fileOut = new FileOutputStream(contextDestination); 53 | oos = new ObjectOutputStream(fileOut); 54 | oos.writeObject(launchContext); 55 | 56 | javaExec.setWorkingDir(launchContext.getBaseDir()); 57 | if (launchContext.getGrailsHome() != null) { 58 | javaExec.systemProperty("grails.home", launchContext.getGrailsHome().getAbsolutePath()); 59 | } 60 | 61 | File launcherJar = findJarFile(ForkedGrailsLauncher.class); 62 | javaExec.classpath(launcherJar); 63 | javaExec.setMain(Main.class.getName()); 64 | javaExec.args(contextDestination.getAbsolutePath()); 65 | } catch (IOException e) { 66 | throw new RuntimeException(e); 67 | } finally { 68 | try { 69 | if (oos != null) { 70 | oos.close(); 71 | } 72 | if (fileOut != null) { 73 | fileOut.close(); 74 | } 75 | } catch (IOException ignore) { 76 | 77 | } 78 | } 79 | } 80 | 81 | public void configureReloadAgent(JavaExecSpec exec) { 82 | if (springloadedJar == null) { 83 | return; 84 | } 85 | 86 | String agentJarFilePath = springloadedJar.getAbsolutePath(); 87 | 88 | // Workaround http://issues.gradle.org/browse/GRADLE-2485 89 | Boolean isDebug = exec.getDebug(); 90 | exec.jvmArgs(String.format("-javaagent:%s", agentJarFilePath), "-noverify"); 91 | if (isDebug) { 92 | exec.setDebug(true); 93 | } 94 | exec.systemProperty("springloaded", "profile=grails"); 95 | } 96 | 97 | private File findJarFile(Class targetClass) { 98 | String absolutePath = targetClass.getResource('/' + targetClass.getName().replace(".", "/") + ".class").getPath(); 99 | String jarPath = absolutePath.substring("file:".length(), absolutePath.lastIndexOf("!")); 100 | return new File(jarPath); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/tasks/GrailsAssembleTask.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.tasks 2 | 3 | import org.gradle.api.tasks.OutputFile 4 | import org.gradle.api.tasks.TaskInstantiationException 5 | 6 | class GrailsAssembleTask extends GrailsTask { 7 | 8 | protected CharSequence output 9 | 10 | void setOutputFile(CharSequence file) { 11 | this.output = file 12 | } 13 | 14 | void setOutputFile(File file) { 15 | this.output = file.path 16 | } 17 | 18 | @OutputFile 19 | File getOutputFile() { 20 | return project.file(this.output) 21 | } 22 | } 23 | 24 | class GrailsPluginPackageTask extends GrailsAssembleTask { 25 | 26 | GrailsPluginPackageTask() { 27 | super.setOutputFile((CharSequence) "grails-${project.name}-${->project.version}.zip") 28 | command = 'package-plugin' 29 | description = 'Packages a grails plugin' 30 | } 31 | 32 | @Override 33 | void setOutputFile(CharSequence file) { 34 | throw new TaskInstantiationException("Assemble task for Grails Plugins is not configurable") 35 | } 36 | 37 | @Override 38 | void setOutputFile(File file) { 39 | throw new TaskInstantiationException("Assemble task for Grails Plugins is not configurable") 40 | } 41 | 42 | } 43 | 44 | class GrailsWarTask extends GrailsAssembleTask { 45 | 46 | GrailsWarTask() { 47 | super.setOutputFile((CharSequence) "build/distributions/${project.name}-${->project.version}.war") 48 | command = "war" 49 | description = 'Generates the application WAR file' 50 | } 51 | 52 | @Override 53 | CharSequence getArgs() { 54 | return "${-> output} ${-> super.args}" 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/tasks/GrailsEclipseJdtGroovyTask.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.tasks 18 | 19 | import org.gradle.api.internal.ConventionTask 20 | import org.gradle.api.tasks.Input 21 | import org.gradle.api.tasks.OutputFile 22 | import org.gradle.api.tasks.TaskAction 23 | import org.gradle.plugins.ide.eclipse.EclipsePlugin 24 | 25 | /** 26 | * Created by Jeevanandam M. (jeeva@myjeeva.com) on 7/8/14. 27 | */ 28 | class GrailsEclipseJdtGroovyTask extends ConventionTask { 29 | // Constants 30 | static final ECLIPSE_SETTINGS_DIR_NAME = '.settings' 31 | static final ECLIPSE_GROOVY_JDT_PREFS_FILE = "${ECLIPSE_SETTINGS_DIR_NAME}${File.separator}org.eclipse.jdt.groovy.core.prefs" 32 | static final ECLIPSE_JDT_GROOVY_CLEAN_TASK_NAME = "cleanEclipseJdtGroovy" 33 | static final ECLIPSE_JDT_GROOVY_TASK_NAME = "eclipseJdtGroovy" 34 | 35 | @Input 36 | String getGroovyVersion() { 37 | return project.grails.groovyVersion ?: '2.1.9' // Just defaulting to 2.1 compiler for IDE 38 | } 39 | 40 | @OutputFile 41 | File outputFile 42 | 43 | GrailsEclipseJdtGroovyTask() { 44 | super() 45 | description = 'Generates the Eclipse JDT Groovy settings file.' 46 | outputFile = project.file(ECLIPSE_GROOVY_JDT_PREFS_FILE) 47 | 48 | project.tasks.findByName(EclipsePlugin.ECLIPSE_TASK_NAME)?.dependsOn(ECLIPSE_JDT_GROOVY_TASK_NAME) 49 | } 50 | 51 | @TaskAction 52 | def createJdtGroovyPrefs() { 53 | def groovyCompilerVersion = getGroovyVersion()[0..2].replaceAll(/\./, "") 54 | 55 | def file = getOutputFile() 56 | if (!file.isFile()) { 57 | file.parentFile.mkdirs() 58 | file.createNewFile() 59 | } 60 | 61 | def props = new Properties() 62 | props.load(file.newDataInputStream()) 63 | props.setProperty('eclipse.preferences.version', '1') 64 | props.setProperty('groovy.compiler.level', groovyCompilerVersion) 65 | props.store(file.newWriter(), null) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/tasks/GrailsInitTask.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.tasks 2 | 3 | import org.gradle.api.InvalidUserDataException 4 | import org.gradle.api.tasks.TaskAction 5 | 6 | /** 7 | * Creates a new Grails application in the working directory. This requires that the 'project.version' property 8 | * be configured in the Gradle build. 9 | * 10 | * By default this will create the Grails application with a name matching the projectDir name. This can be overridden 11 | * on the command line by supplying '-PgrailsArgs=' when executing the command 12 | */ 13 | class GrailsInitTask extends GrailsTask { 14 | 15 | GrailsInitTask() { 16 | onlyIf { 17 | !project.file("application.properties").exists() && !project.file("grails-app").exists() 18 | } 19 | 20 | def projName = project.hasProperty(GRAILS_ARGS_PROPERTY) ? project.property(GRAILS_ARGS_PROPERTY) : project.projectDir.name 21 | 22 | command = "create-app" 23 | args = "--inplace --appVersion=${ -> project.version} $projName" 24 | description = 'Creates a new Grails application in the current directory' 25 | } 26 | 27 | @TaskAction 28 | def executeCommand() { 29 | if (project.version == "unspecified") { 30 | throw new InvalidUserDataException("[GrailsPlugin] Build file must specify a 'version' property.") 31 | } 32 | super.executeCommand() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/tasks/GrailsTask.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.tasks 18 | 19 | import org.gradle.api.Action 20 | import org.gradle.api.DefaultTask 21 | import org.gradle.api.InvalidUserDataException 22 | import org.gradle.api.file.FileCollection 23 | import org.gradle.api.internal.file.FileResolver 24 | import org.gradle.api.tasks.* 25 | import org.gradle.process.ExecResult 26 | import org.gradle.process.JavaForkOptions 27 | import org.gradle.process.internal.DefaultJavaForkOptions 28 | import org.gradle.process.internal.ExecException 29 | import org.gradle.process.internal.JavaExecAction 30 | import org.grails.gradle.plugin.internal.GrailsLaunchConfigureAction 31 | import org.grails.launcher.context.GrailsLaunchContext 32 | import org.grails.launcher.context.SerializableGrailsLaunchContext 33 | import org.grails.launcher.util.NameUtils 34 | import org.grails.launcher.version.GrailsVersion 35 | import org.grails.launcher.version.GrailsVersionParser 36 | 37 | /** 38 | * Base class for all Grails tasks 39 | */ 40 | class GrailsTask extends DefaultTask { 41 | 42 | static public final GRAILS_TASK_PREFIX = "grails-" 43 | static public final GRAILS_ARGS_PROPERTY = 'grailsArgs' 44 | static public final GRAILS_ENV_PROPERTY = 'grailsEnv' 45 | static public final GRAILS_DEBUG_PROPERTY = 'grailsDebug' 46 | static public final GRAILS_GROUP = 'grails' 47 | 48 | static public final String APP_GRAILS_VERSION = 'app.grails.version' 49 | static public final String APP_VERSION = 'app.version' 50 | 51 | String grailsVersion 52 | 53 | String grailsHome 54 | String command 55 | CharSequence args 56 | String env 57 | boolean reload 58 | 59 | @Optional @InputFiles FileCollection providedClasspath 60 | @Optional @InputFiles FileCollection compileClasspath 61 | @Optional @InputFiles FileCollection runtimeClasspath 62 | @Optional @InputFiles FileCollection testClasspath 63 | 64 | @Optional @InputFiles FileCollection springloaded 65 | 66 | @InputFiles FileCollection bootstrapClasspath 67 | 68 | boolean useRuntimeClasspathForBootstrap 69 | 70 | JavaForkOptions jvmOptions 71 | SourceSetContainer sourceSets 72 | 73 | private projectDir 74 | private projectWorkDir 75 | private boolean pluginProject 76 | 77 | boolean forwardStdIn 78 | boolean captureOutputToInfo 79 | 80 | GrailsTask() { 81 | this.jvmOptions = new DefaultJavaForkOptions(getServices().get(FileResolver)) 82 | command = name 83 | group = GRAILS_GROUP 84 | } 85 | 86 | @Input 87 | File getProjectDir() { 88 | projectDir == null ? null : project.file(projectDir) 89 | } 90 | 91 | @Input 92 | File getProjectWorkDir() { 93 | projectWorkDir == null ? null : project.file(projectWorkDir) 94 | } 95 | 96 | File getGrailsHome() { 97 | grailsHome == null ? null : project.file(grailsHome) 98 | } 99 | 100 | public JavaForkOptions getJvmOptions() { 101 | return jvmOptions 102 | } 103 | 104 | public void jvmOptions(Action configure) { 105 | project.configure(jvmOptions, { configure.execute(it) }) 106 | } 107 | 108 | @TaskAction 109 | def executeCommand() { 110 | handleVersionSync() 111 | def launchContext = createLaunchContext() 112 | def file = new File(getTemporaryDir(), "launch.context") 113 | 114 | def springloaded = getSpringloaded() 115 | def springloadedJar 116 | if (springloaded == null || !isReload()) { 117 | springloadedJar == null 118 | } else { 119 | springloadedJar = springloaded.singleFile 120 | } 121 | 122 | def launcher = new GrailsLaunchConfigureAction(launchContext, springloadedJar, file) 123 | 124 | // Capture output and only display to console in error conditions 125 | // if capture is enabled and info logging is not enabled. 126 | def capture = captureOutputToInfo && !logger.infoEnabled 127 | OutputStream out = capture ? new ByteArrayOutputStream() : System.out 128 | OutputStream err = capture ? new ByteArrayOutputStream() : System.err 129 | 130 | ExecResult result = project.javaexec { 131 | JavaExecAction action = delegate 132 | action.ignoreExitValue = true 133 | getJvmOptions().copyTo(action) 134 | if (forwardStdIn) { 135 | action.standardInput = System.in 136 | } 137 | action.standardOutput = out 138 | action.errorOutput = err 139 | launcher.execute(action) 140 | } 141 | 142 | try { 143 | checkExitValue(result) 144 | } catch (ExecException e) { 145 | if (capture) { 146 | if (out instanceof ByteArrayOutputStream) { 147 | out.writeTo(System.out) 148 | } 149 | if (err instanceof ByteArrayOutputStream) { 150 | err.writeTo(System.err) 151 | } 152 | } 153 | throw e 154 | } 155 | } 156 | 157 | protected void checkExitValue(ExecResult result) { 158 | result.rethrowFailure() 159 | result.assertNormalExitValue() 160 | } 161 | 162 | File getEffectiveGrailsHome() { 163 | getGrailsHome() ?: (project.hasProperty('grailsHome') ? project.file(project.grailsHome) : null) 164 | } 165 | 166 | protected GrailsVersion getParsedGrailsVersion() { 167 | new GrailsVersionParser().parse(getGrailsVersion() ?: project.grailsVersion) 168 | } 169 | 170 | boolean isEffectiveUseRuntimeClasspathForBootstrap() { 171 | getCommand() in ["run-app", "test-app", "release-plugin"] || isUseRuntimeClasspathForBootstrap() 172 | } 173 | 174 | protected void addToolsJarIfNecessary(Collection classpath) { 175 | // Add the "tools.jar" to the classpath so that the Grails 176 | // scripts can run native2ascii. First assume that "java.home" 177 | // points to a JRE within a JDK. 178 | def javaHome = System.getProperty("java.home"); 179 | def toolsJar = new File(javaHome, "../lib/tools.jar"); 180 | if (!toolsJar.exists()) { 181 | // The "tools.jar" cannot be found with that path, so 182 | // now try with the assumption that "java.home" points 183 | // to a JDK. 184 | toolsJar = new File(javaHome, "tools.jar"); 185 | } 186 | 187 | // There is no tools.jar, so native2ascii may not work. Note 188 | // that on Mac OS X, native2ascii is already on the classpath. 189 | if (!toolsJar.exists() && !System.getProperty('os.name') == 'Mac OS X') { 190 | project.logger.warn "[GrailsPlugin] Cannot find tools.jar in JAVA_HOME, so native2ascii may not work." 191 | } 192 | 193 | if (toolsJar.exists()) { 194 | classpath << toolsJar 195 | } 196 | } 197 | 198 | protected Collection getEffectiveBootstrapClasspath() { 199 | def classpath = getBootstrapClasspath().files 200 | if (isEffectiveUseRuntimeClasspathForBootstrap()) { 201 | classpath.addAll(getRuntimeClasspath().files) 202 | } 203 | addToolsJarIfNecessary(classpath) 204 | classpath 205 | } 206 | 207 | protected GrailsLaunchContext createLaunchContext() { 208 | GrailsLaunchContext launchContext = new SerializableGrailsLaunchContext(getParsedGrailsVersion()) 209 | 210 | launchContext.dependenciesExternallyConfigured = true 211 | launchContext.plainOutput = true 212 | 213 | launchContext.grailsHome = getEffectiveGrailsHome() 214 | launchContext.baseDir = getProjectDir() 215 | launchContext.env = getEnv() 216 | 217 | launchContext.scriptName = NameUtils.toScriptName(getCommand()) 218 | launchContext.args = (getArgs() ? getArgs() + ' ' : '') + '--non-interactive' 219 | 220 | Iterable files = getEffectiveBootstrapClasspath() 221 | if (files) { 222 | launchContext.buildDependencies = files as List 223 | } 224 | 225 | files = getCompileClasspath() 226 | if (files) { 227 | launchContext.compileDependencies = files as List 228 | } 229 | 230 | files = getTestClasspath() 231 | if (files) { 232 | launchContext.testDependencies = files as List 233 | } 234 | 235 | files = getRuntimeClasspath() 236 | if (files) { 237 | launchContext.runtimeDependencies = files as List 238 | } 239 | 240 | // Provided deps are 2.0 only 241 | files = getProvidedClasspath() 242 | if (files) { 243 | try { 244 | launchContext.providedDependencies = files as List 245 | } catch (NoSuchMethodException ignore) { 246 | throw new InvalidUserDataException("Cannot set provided classpath for task ${this} as this version of Grails does not support provided dependencies") 247 | } 248 | } 249 | 250 | launchContext.projectWorkDir = getProjectWorkDir() 251 | launchContext.classesDir = projectWorkDirFile("classes") 252 | launchContext.testClassesDir = projectWorkDirFile("test-classes") 253 | launchContext.resourcesDir = projectWorkDirFile("resources") 254 | launchContext.projectPluginsDir = projectDirFile("buildPlugins") 255 | launchContext.testReportsDir = projectWorkDirFile("test-results") 256 | 257 | launchContext 258 | } 259 | 260 | void logClasspaths() { 261 | project.logger.with { 262 | quiet "Classpath for Grails root loader:\n ${getEffectiveBootstrapClasspath().join('\n ')}" 263 | quiet "Compile classpath:\n ${getCompileClasspath().files.join('\n ')}" 264 | quiet "Test classpath:\n ${getTestClasspath().files.join('\n ')}" 265 | quiet "Runtime classpath:\n ${getRuntimeClasspath().files.join('\n ')}" 266 | } 267 | } 268 | 269 | protected boolean isPluginProject() { 270 | getProjectDir().listFiles({ dir, name -> name ==~ /.*GrailsPlugin.groovy/} as FilenameFilter) as boolean 271 | } 272 | 273 | protected File projectDirFile(String path) { 274 | new File(getProjectDir(), path) 275 | } 276 | 277 | protected File projectWorkDirFile(String path) { 278 | new File(getProjectWorkDir(), path) 279 | } 280 | 281 | private void handleVersionSync() { 282 | File appProperties = project.file('application.properties') 283 | URLClassLoader cl = new URLClassLoader(effectiveBootstrapClasspath.collect { it.toURI().toURL() } as URL[]) 284 | Class metadataClass = cl.loadClass('grails.util.Metadata') 285 | Object metadata = metadataClass.newInstance(appProperties) 286 | if (syncVersions(metadata)) { 287 | metadata.persist() 288 | } 289 | } 290 | 291 | private boolean syncVersions(Object metadata) { 292 | boolean result = false 293 | 294 | Object appGrailsVersion = metadata.get(APP_GRAILS_VERSION) 295 | if (!getGrailsVersion().equals(appGrailsVersion)) { 296 | logger.info("updating ${APP_GRAILS_VERSION} to ${getGrailsVersion()}") 297 | metadata.put(APP_GRAILS_VERSION, this.getGrailsVersion()) 298 | result = true 299 | } 300 | 301 | if (!isPluginProject()) { 302 | Object appVersion = metadata.get(APP_VERSION) 303 | if (appVersion != null) { 304 | if (!project.version.equals(appVersion)) { 305 | logger.info("updating ${APP_VERSION} to ${project.version}") 306 | metadata.put(APP_VERSION, project.version) 307 | result = true 308 | } 309 | } 310 | } else { 311 | syncPluginVersion() 312 | } 313 | 314 | return result 315 | } 316 | 317 | // Reimplemented from https://github.com/grails/grails-core/blob/master/scripts/SetVersion.groovy 318 | private void syncPluginVersion() { 319 | File descriptor = project.grails.getPluginDescriptor() 320 | String content = descriptor.getText('UTF-8') 321 | def pattern = ~/def\s*version\s*=\s*"(.*)"/ 322 | def matcher = (content =~ pattern) 323 | 324 | String newVersionString = "def version = \"${project.version}\"" 325 | if (matcher.size() > 0) { 326 | content = content.replaceFirst(/def\s*version\s*=\s*".*"/, newVersionString) 327 | } else { 328 | content = content.replaceFirst(/\{/, "{\n\t$newVersionString // added by Gradle") 329 | } 330 | descriptor.withWriter('UTF-8') { it.write content } 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/tasks/GrailsTaskConfigurator.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.tasks 2 | 3 | import org.gradle.api.DefaultTask 4 | import org.gradle.api.Project 5 | import org.gradle.api.Task 6 | import org.gradle.api.plugins.BasePlugin 7 | import org.gradle.api.plugins.JavaBasePlugin 8 | import org.gradle.api.plugins.JavaPlugin 9 | import org.gradle.api.plugins.WarPlugin 10 | import org.grails.gradle.plugin.GrailsProject 11 | 12 | /** 13 | * Configures the default Grails tasks and wires them into the standard build process: 14 | * ('build', 'check', 'test', 'assemble') 15 | */ 16 | class GrailsTaskConfigurator { 17 | 18 | public static final String GRAILS_INIT_TASK = 'init' 19 | public static final String GRAILS_INIT_PLUGIN_TASK = 'init-plugin' 20 | public static final String GRAILS_TEST_TASK = JavaPlugin.TEST_TASK_NAME 21 | public static final String GRAILS_RUN_TASK = 'run' 22 | public static final String GRAILS_PACKAGE_PLUGIN_TASK = 'packagePlugin' 23 | public static final String GRAILS_WAR_TASK = WarPlugin.WAR_TASK_NAME 24 | 25 | void configure(Project project, GrailsProject grailsProject) { 26 | //Create the Grails init task 27 | project.tasks.create(GRAILS_INIT_TASK, GrailsInitTask) 28 | 29 | //Create the Grails init plugin task 30 | project.tasks.create(GRAILS_INIT_PLUGIN_TASK, GrailsInitTask).with { 31 | command = 'create-plugin' 32 | description = 'Creates a new Grails plugin in the current directory' 33 | } 34 | 35 | project.tasks.getByName(BasePlugin.CLEAN_TASK_NAME) { 36 | delete 'buildPlugins', 'plugin.xml', "grails-${project.name}-${-> project.version}.zip" 37 | } 38 | 39 | //Set up the proper assemble task and adds it's artifact to the configuration 40 | configureAssemble(grailsProject, project) 41 | 42 | //Add the run task...this is allowable for both applications and plugins 43 | project.tasks.create(GRAILS_RUN_TASK, GrailsTask).with { 44 | command = 'run-app' 45 | description = 'Starts the Grails application' 46 | reload = true 47 | } 48 | 49 | //Create the Grails test task. 50 | project.tasks.create(GRAILS_TEST_TASK, GrailsTestTask) 51 | 52 | //Create a task rule that converts any task with that starts with 'grail-' into an invocation of 53 | //the corresponding Grails script 54 | project.tasks.addRule("Pattern: ${GrailsTask.GRAILS_TASK_PREFIX}: Execute the specified Grails script") { String name -> 55 | if (name.startsWith(GrailsTask.GRAILS_TASK_PREFIX)) { 56 | project.task(name, type: GrailsTask) { 57 | String scriptName = name - GrailsTask.GRAILS_TASK_PREFIX 58 | command = scriptName 59 | if (project.hasProperty(GrailsTask.GRAILS_ARGS_PROPERTY)) { 60 | args = project.property(GrailsTask.GRAILS_ARGS_PROPERTY) 61 | } 62 | if (project.hasProperty(GrailsTask.GRAILS_ENV_PROPERTY)) { 63 | env = project.property(GrailsTask.GRAILS_ENV_PROPERTY) 64 | } 65 | if (scriptName == 'run-app') { 66 | reload = true 67 | } 68 | } 69 | } 70 | } 71 | 72 | project.tasks.withType(GrailsTask) { 73 | if (project.hasProperty(GrailsTask.GRAILS_DEBUG_PROPERTY)) { 74 | jvmOptions.debug = Boolean.parseBoolean(project.property(GrailsTask.GRAILS_DEBUG_PROPERTY)) 75 | } 76 | } 77 | 78 | //Setup some tasks that mimic the Java build pattern 79 | configureJavaStyleTasks(project) 80 | } 81 | 82 | private GrailsAssembleTask createPackagePluginTask(Project project) { 83 | project.tasks.create(GRAILS_PACKAGE_PLUGIN_TASK, GrailsPluginPackageTask) 84 | return project.tasks.findByName(GRAILS_PACKAGE_PLUGIN_TASK) 85 | } 86 | 87 | private GrailsAssembleTask createWarTask(Project project) { 88 | GrailsAssembleTask war = project.tasks.create(GRAILS_WAR_TASK, GrailsWarTask) 89 | war.env = 'production' 90 | return project.tasks.findByName(GRAILS_WAR_TASK) 91 | } 92 | 93 | /** 94 | * Wire up the Grails project into the standard Gradle Java build flow (mimic the Java Plugin) 95 | */ 96 | private void configureJavaStyleTasks(Project project) { 97 | configureCheck(project) 98 | configureBuild(project) 99 | configureTest(project) 100 | } 101 | 102 | /** 103 | * Add the 'check' task 104 | */ 105 | private void configureCheck(Project project) { 106 | if (!project.tasks.findByName(JavaBasePlugin.CHECK_TASK_NAME)) { 107 | project.tasks.create(JavaBasePlugin.CHECK_TASK_NAME) 108 | } 109 | Task checkTask = project.tasks.findByName(JavaBasePlugin.CHECK_TASK_NAME) 110 | checkTask.setDescription("Runs all checks.") 111 | checkTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP) 112 | } 113 | 114 | /** 115 | * Add the 'build' task and wire it to 'check' and 'assemble' 116 | */ 117 | private void configureBuild(Project project) { 118 | if (!project.tasks.findByName(JavaBasePlugin.BUILD_TASK_NAME)) { 119 | project.tasks.create(JavaBasePlugin.BUILD_TASK_NAME, DefaultTask.class) 120 | } 121 | DefaultTask buildTask = project.tasks.findByName(JavaBasePlugin.BUILD_TASK_NAME) 122 | buildTask.setDescription("Assembles and tests this project.") 123 | buildTask.setGroup(BasePlugin.BUILD_GROUP) 124 | buildTask.dependsOn(BasePlugin.ASSEMBLE_TASK_NAME) 125 | buildTask.dependsOn(JavaBasePlugin.CHECK_TASK_NAME) 126 | } 127 | 128 | /** 129 | * Add the 'test' task and wire it to 'check' 130 | */ 131 | private void configureTest(Project project) { 132 | Task test = project.tasks.findByName(JavaPlugin.TEST_TASK_NAME) 133 | project.tasks.getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(test) 134 | test.setDescription("Runs the tests.") 135 | } 136 | 137 | private void configureAssemble(GrailsProject grailsProject, Project project) { 138 | //Depending on the project type, configure either the package-plugin or war tasks 139 | //as the assemble task 140 | GrailsAssembleTask grailsAssemble = grailsProject.pluginProject ? 141 | createPackagePluginTask(project) : createWarTask(project) 142 | 143 | project.tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn grailsAssemble 144 | project.configurations.default.extendsFrom(project.configurations.runtime) 145 | project.afterEvaluate { 146 | project.artifacts.add('runtime', grailsAssemble.outputFile) { 147 | type grailsAssemble.outputFile.path.tokenize('.').last() 148 | builtBy grailsAssemble 149 | } 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/main/groovy/org/grails/gradle/plugin/tasks/GrailsTestTask.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.tasks 2 | 3 | import org.gradle.api.tasks.Input 4 | import org.gradle.api.tasks.InputFiles 5 | import org.gradle.api.tasks.Optional 6 | import org.gradle.api.tasks.OutputDirectories 7 | import org.gradle.api.tasks.OutputDirectory 8 | import org.gradle.process.ExecResult 9 | import org.grails.launcher.context.GrailsLaunchContext 10 | 11 | /** 12 | * Executes Grails tests. By default this command will execute all the Grails test phases and types. A single test can 13 | * be executed by supplying '-Ptest.single=' when executing this task. 14 | * 15 | * Additionally, the test phases/types to executes can by configured by configuring the 'phases' property. This list 16 | * should contain the phases/types in the standard Grails format: ['unit:', 'integration:'], ['unit:spock'] 17 | * 18 | * This tasks also tracks the Grails source as task inputs/outputs for up-to-date checking. If this behavior is 19 | * undesirably, configure the task with 'outputs.upToDateWhen { false }'. 20 | * 21 | * The plugin configures a task of this type (grails-test-app) as a dependency of the 'test' task. 22 | */ 23 | class GrailsTestTask extends GrailsTask { 24 | 25 | @OutputDirectory 26 | @Optional 27 | File testResultsDir 28 | 29 | private List phases 30 | private String grailsArgs 31 | private boolean ignoreFailures = false; 32 | 33 | GrailsTestTask() { 34 | super() 35 | command = 'test-app' 36 | env = 'test' 37 | description = 'Executes Grails tests' 38 | } 39 | 40 | @InputFiles 41 | Set getSourceInputs() { 42 | sourceSets.getByName('main').allSource.files + sourceSets.getByName('test').allSource.files 43 | } 44 | 45 | @OutputDirectories 46 | Set getSourceOutputs() { 47 | [sourceSets.getByName('main').output.classesDir, sourceSets.getByName('test').output.classesDir] 48 | } 49 | 50 | @Override 51 | protected GrailsLaunchContext createLaunchContext() { 52 | GrailsLaunchContext ctx = super.createLaunchContext() 53 | if (testResultsDir) { 54 | ctx.testReportsDir = testResultsDir 55 | } 56 | return ctx 57 | } 58 | 59 | void setPhases(List phases) { 60 | this.phases = phases 61 | } 62 | 63 | void setArgs(String args) { 64 | grailsArgs = args 65 | } 66 | 67 | void setIgnoreFailures(boolean ignoreFailures) { 68 | this.ignoreFailures = ignoreFailures 69 | } 70 | 71 | @Override 72 | @Input 73 | String getArgs() { 74 | [phases?.join(' '), grailsArgs, testSingle].findAll { it }.join(' ') 75 | } 76 | 77 | String getTestSingle() { 78 | return System.getProperty('test.single', '') 79 | } 80 | 81 | @Override 82 | protected void checkExitValue(ExecResult result) { 83 | if(!ignoreFailures) { 84 | super.checkExitValue(result) 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/grails.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.grails.gradle.plugin.GrailsPlugin 2 | -------------------------------------------------------------------------------- /src/main/resources/grails-maven/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 2 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 3 | # Enable logging for everything. Rarely useful 4 | log4j.rootLogger=error, stdout 5 | 6 | 7 | # This logger is for your own application artefact logs 8 | # Artefacts are logged by their type and optionally class name i.e: 9 | # 10 | # log4j.logger.grails.app.controller.HelloController=debug, stdout 11 | # ...will control the logs from just that controller 12 | # 13 | # log4j.logger.grails.app.domain=trace, stdout 14 | # ...will control the logs for all domain classes 15 | # 16 | # At the time of writing, supported artefact type ids include: 17 | # domain (aka Domain Class), service, dataSource, 18 | # controller, tagLib, urlMappings, codec, bootstrap 19 | # 20 | # The default "info" level for all artefacts is set here 21 | log4j.logger.grails.app=info,stdout 22 | log4j.additivity.grails.app=false 23 | 24 | ## This logger is for Grails' public APIs within the grails. package 25 | log4j.logger.grails=info,stdout 26 | log4j.additivity.grails=false 27 | 28 | ## Enable this logger to log Hibernate output 29 | # handy to see its database interaction activity 30 | #log4j.logger.org.hibernate=debug,stdout 31 | #log4j.additivity.org.hibernate=false 32 | 33 | # Enable this logger to see what Spring does, occasionally useful 34 | #log4j.logger.org.springframework=info,stdout 35 | #log4j.additivity.org.springframework=false 36 | 37 | # This logger covers all of Grails' internals 38 | # Enable to see whats going on underneath. 39 | log4j.logger.org.codehaus.groovy.grails=info,stdout 40 | log4j.additivity.org.codehaus.groovy.grails=false 41 | 42 | # This logger is useful if you just want to see what Grails 43 | # configures with Spring at runtime. Setting to debug will show 44 | # each bean that is configured 45 | log4j.logger.org.codehaus.groovy.grails.commons.spring=info,stdout 46 | log4j.additivity.org.codehaus.groovy.grails.commons.spring=false 47 | 48 | # Interesting Logger to see what some of the Grails factory beans are doing 49 | log4j.logger.org.codehaus.groovy.grails.beans.factory=info,stdout 50 | log4j.additivity.org.codehaus.groovy.grails.beans.factory=false 51 | 52 | # This logger outputs what Grails is doing dynamically under the covers 53 | log4j.logger.org.codehaus.groovy.grails.commons.metaclass=info,stdout 54 | log4j.additivity.org.codehaus.groovy.grails.commons.metaclass=false 55 | 56 | # These two loggers are for tracking what plugins are doing 57 | log4j.logger.org.codehaus.groovy.grails.plugins=info,stdout 58 | log4j.additivity.org.codehaus.groovy.grails.plugins=false 59 | log4j.logger.grails.spring=info,stdout 60 | log4j.additivity.grails.spring=false 61 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/IdeaConfigurationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin 18 | 19 | class IdeaConfigurationSpec extends PluginSpec { 20 | 21 | def setup() { 22 | project.apply plugin: 'idea' 23 | } 24 | 25 | def "idea module has scopes configured"() { 26 | expect: 27 | project.idea.module.scopes.keySet() == ['PROVIDED', 'COMPILE', 'RUNTIME', 'TEST'] as Set 28 | 29 | and: 30 | project.configurations.provided in project.idea.module.scopes.PROVIDED.plus 31 | project.configurations.compile in project.idea.module.scopes.COMPILE.plus 32 | project.configurations.runtime in project.idea.module.scopes.RUNTIME.plus 33 | project.configurations.compile in project.idea.module.scopes.RUNTIME.minus 34 | project.configurations.test in project.idea.module.scopes.TEST.plus 35 | project.configurations.runtime in project.idea.module.scopes.TEST.minus 36 | } 37 | 38 | def "idea modules has project source and test source configured"() { 39 | expect: 40 | [ 41 | 'src/groovy', 'src/java', 'grails-app/controllers', 42 | 'grails-app/domain', 'grails-app/services', 'grails-app/taglib' 43 | ].each { 44 | def directory = project.file(it) 45 | assert project.idea.module.sourceDirs.contains(directory) 46 | } 47 | 48 | and: 49 | [ 50 | 'test/unit', 'test/integration', 'test/functional' 51 | ].each { 52 | def directory = project.file(it) 53 | assert project.idea.module.testSourceDirs.contains(directory) 54 | } 55 | } 56 | 57 | def "idea module has plugin source directories configured"() { 58 | given: 59 | project.dependencies { 60 | bootstrap 'org.grails.plugins:tomcat:7.0.50.1' 61 | compile 'org.grails.plugins:resources:1.2.2' 62 | runtime 'org.grails.plugins:zipped-resources:1.0.1' 63 | test 'org.grails.plugins:build-test-data:2.1.1' 64 | } 65 | def srcDirs = [ 66 | 'src/groovy', 'src/java', 'grails-app/controllers', 67 | 'grails-app/domain', 'grails-app/services', 'grails-app/taglib' 68 | ] 69 | 70 | expect: 71 | ['tomcat-7.0.50.1', 'resources-1.2.2', 'zipped-resources-1.0.1'].each { plugin -> 72 | srcDirs.each { subdir -> 73 | def directory = project.file("buildPlugins/$plugin/$subdir") 74 | assert project.idea.module.sourceDirs.contains(directory) 75 | } 76 | } 77 | 78 | and: 79 | assert !project.idea.module.sourceDirs.any { 80 | it.path.startsWith(project.file('buildPlugins/build-test-data-2.1.1').path) 81 | } 82 | 83 | and: 84 | srcDirs.each { subdir -> 85 | def directory = project.file("buildPlugins/build-test-data-2.1.1/$subdir") 86 | assert project.idea.module.testSourceDirs.contains(directory) 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/PluginSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin 18 | 19 | import org.gradle.api.Project 20 | import org.gradle.testfixtures.ProjectBuilder 21 | import org.grails.gradle.plugin.tasks.GrailsTask 22 | import spock.lang.Specification 23 | 24 | class PluginSpec extends Specification { 25 | 26 | Project project = ProjectBuilder.builder().build() 27 | 28 | def setup() { 29 | project.apply plugin: "grails" 30 | project.grails.grailsVersion = '2.0.0' 31 | } 32 | 33 | GrailsTask grailsTask(String name, Closure config = {}) { 34 | GrailsTask task = project.task(name, type: GrailsTask, config) as GrailsTask 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/TaskConfigurationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin 18 | 19 | import org.gradle.testfixtures.ProjectBuilder 20 | import org.grails.gradle.plugin.tasks.GrailsPluginPackageTask 21 | import org.grails.gradle.plugin.tasks.GrailsWarTask 22 | 23 | class TaskConfigurationSpec extends PluginSpec { 24 | 25 | def "basic tasks are in place"() { 26 | given: 27 | def baseTasks = ['check', 'build', 'assemble', 'clean'] 28 | def grailsTasks = ['init', 'init-plugin', 'test', 'run', 'war'] 29 | 30 | expect: 31 | (baseTasks + grailsTasks).each { 32 | assert project.tasks.findByName(it) 33 | } 34 | } 35 | 36 | def "default configuration extends the runtime configuration"() { 37 | expect: 38 | project.configurations.default.extendsFrom.contains(project.configurations.runtime) 39 | } 40 | 41 | def "war task defaults to production environment"() { 42 | expect: 43 | project.tasks.findByName('war').getEnv() == 'production' 44 | } 45 | 46 | def "war file is configured as runtime artifact for application"() { 47 | given: 48 | project.evaluate() 49 | List artifactFiles = project.configurations.runtime.artifacts.files.files as List 50 | 51 | expect: 52 | assert artifactFiles.size() == 1 53 | assert artifactFiles.first() == project.file("build/distributions/${project.name}-${project.version}.war") 54 | 55 | and: 56 | assert project.configurations.default.allArtifacts.files.files.toList().first() == 57 | project.file("build/distributions/${project.name}-${project.version}.war") 58 | 59 | } 60 | 61 | def "version is included in war file name"() { 62 | given: 63 | project.version = '1.0' 64 | project.evaluate() 65 | List artifactFiles = project.configurations.runtime.artifacts.files.files as List 66 | 67 | expect: 68 | GrailsWarTask war = project.tasks.getByName('war') 69 | assert war.outputFile.path == project.file("build/distributions/${project.name}-1.0.war").path 70 | 71 | and: 72 | assert artifactFiles.size() == 1 73 | assert artifactFiles.first() == project.file("build/distributions/${project.name}-1.0.war") 74 | 75 | and: 76 | assert project.configurations.default.allArtifacts.files.files.toList().first() == 77 | project.file("build/distributions/${project.name}-1.0.war") 78 | 79 | } 80 | 81 | def "zip file is configured as runtime artifact for plugin"() { 82 | given: 83 | project = ProjectBuilder.builder().build() 84 | 85 | project.file("${project.name.capitalize()}GrailsPlugin.groovy") << """ 86 | class ${project.name.capitalize()}GrailsPlugin { } 87 | """ 88 | project.apply plugin: "grails" 89 | project.grails.grailsVersion = '2.0.0' 90 | project.evaluate() 91 | List artifactFiles = project.configurations.runtime.artifacts.files.files as List 92 | 93 | expect: 94 | assert artifactFiles.size() == 1 95 | assert artifactFiles.first() == project.file("grails-${project.name}-${project.version}.zip") 96 | 97 | and: 98 | assert project.configurations.default.allArtifacts.files.files.toList().first() == 99 | project.file("grails-${project.name}-${project.version}.zip") 100 | 101 | and: 102 | assert project.tasks.findByName('packagePlugin') 103 | } 104 | 105 | def "version included in zip file artifact for plugin"() { 106 | given: 107 | project = ProjectBuilder.builder().build() 108 | 109 | project.file("${project.name.capitalize()}GrailsPlugin.groovy") << """ 110 | class ${project.name.capitalize()}GrailsPlugin { } 111 | """ 112 | project.apply plugin: "grails" 113 | project.grails.grailsVersion = '2.0.0' 114 | project.version = '1.0' 115 | project.evaluate() 116 | List artifactFiles = project.configurations.runtime.artifacts.files.files as List 117 | 118 | expect: 119 | GrailsPluginPackageTask war = project.tasks.getByName('packagePlugin') 120 | assert war.outputFile.path == project.file("grails-${project.name}-1.0.zip").path 121 | 122 | and: 123 | assert artifactFiles.size() == 1 124 | assert artifactFiles.first() == project.file("grails-${project.name}-1.0.zip") 125 | 126 | and: 127 | assert project.configurations.default.allArtifacts.files.files.toList().first() == 128 | project.file("grails-${project.name}-1.0.zip") 129 | 130 | } 131 | 132 | def "command defaults to task name"() { 133 | given: 134 | def task = grailsTask("compile") 135 | 136 | expect: 137 | task.command == "compile" 138 | 139 | when: 140 | task.command = "test" 141 | 142 | then: 143 | task.command == "test" 144 | } 145 | 146 | def "can log task classpath"() { 147 | given: 148 | def task = grailsTask("compile") 149 | task.compileClasspath = project.files("c") 150 | task.runtimeClasspath = project.files("r") 151 | task.testClasspath = project.files("t") 152 | task.bootstrapClasspath = project.files("b") 153 | 154 | when: 155 | task.logClasspaths() 156 | 157 | then: 158 | notThrown(Exception) 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/dependencies/GrailsDependenciesConfigurerSpec.groovy: -------------------------------------------------------------------------------- 1 | package org.grails.gradle.plugin.dependencies 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.artifacts.Configuration 5 | import org.gradle.api.artifacts.Dependency 6 | import org.gradle.internal.reflect.Instantiator 7 | import org.gradle.testfixtures.ProjectBuilder 8 | import org.grails.gradle.plugin.GrailsPlugin 9 | import org.grails.gradle.plugin.GrailsProject 10 | import org.grails.gradle.plugin.internal.DefaultGrailsProject 11 | import org.grails.launcher.version.GrailsVersion 12 | import spock.lang.Specification 13 | import spock.lang.Unroll 14 | 15 | class GrailsDependenciesConfigurerSpec extends Specification { 16 | 17 | Project project 18 | GrailsProject grailsProject 19 | GrailsVersion version 20 | GrailsDependenciesConfigurer dependenciesConfigurer 21 | 22 | def setup() { 23 | project = ProjectBuilder.builder().withName('dependency-spec').build() 24 | grailsProject = new DefaultGrailsProject(project) 25 | version = GrailsVersion.parse('2.3.5') 26 | dependenciesConfigurer = new GrailsDependenciesConfigurer(project, grailsProject, version) 27 | } 28 | 29 | @Unroll 30 | def 'configure springloaded #springLoadedVersion as #dependencyTarget'() { 31 | given: 32 | Configuration configuration = project.configurations.create('springloaded') 33 | 34 | when: 35 | grailsProject.springLoadedVersion = springLoadedVersion 36 | dependenciesConfigurer.configureSpringloaded(configuration) 37 | 38 | then: 39 | configuration.dependencies.size() == 1 40 | def dependency = configuration.dependencies.asList().first() 41 | assert "${dependency.group}:${dependency.name}:${dependency.version}" == dependencyTarget 42 | 43 | where: 44 | springLoadedVersion || dependencyTarget 45 | '1.1.4' || 'org.springsource.springloaded:springloaded-core:1.1.4' 46 | '1.1.5.RELEASE' || 'org.springframework:springloaded:1.1.5.RELEASE' 47 | '1.2.0' || 'org.springframework:springloaded:1.2.0.RELEASE' 48 | } 49 | 50 | def "configure base dependencies"() { 51 | given: 52 | project.plugins.apply GrailsPlugin 53 | GrailsProject grails = project.grails 54 | grails.grailsVersion = applyVersion 55 | 56 | when: 57 | println 'hi' 58 | 59 | then: 60 | interaction { 61 | bootstrap.each { hasDependency(project.configurations.bootstrap, it) } 62 | provided.each { hasDependency(project.configurations.provided, it) } 63 | compile.each { hasDependency(project.configurations.compile, it) } 64 | runtime.each { hasDependency(project.configurations.runtime, it) } 65 | test.each { hasDependency(project.configurations.test, it) } 66 | resources.each { hasDependency(project.configurations.resources, it) } 67 | } 68 | 69 | where: 70 | applyVersion << ['2.3.7', '2.4.0'] 71 | bootstrap << [ 72 | [ 73 | 'org.grails:grails-bootstrap:2.3.7', 74 | 'org.grails:grails-scripts:2.3.7', 75 | 'org.grails:grails-resources:2.3.7', 76 | 77 | ], 78 | [ 79 | 'org.grails:grails-bootstrap:2.4.0', 80 | 'org.grails:grails-scripts:2.4.0', 81 | 'org.grails:grails-resources:2.4.0' 82 | ] 83 | ] 84 | provided << [ 85 | [], [] 86 | ] 87 | compile << [ 88 | [ 89 | 'org.grails:grails-dependencies:2.3.7' 90 | ], 91 | [ 92 | 'org.grails:grails-dependencies:2.4.0', 93 | ] 94 | ] 95 | runtime << [ 96 | [ 97 | 'com.h2database:h2:1.3.170' 98 | ], 99 | [ 100 | 'com.h2database:h2:1.3.170' 101 | ] 102 | ] 103 | test << [ 104 | [ 105 | 'org.grails:grails-plugin-testing:2.3.7', 106 | 'org.grails:grails-test:2.3.7' 107 | ], 108 | [ 109 | 'org.grails:grails-plugin-testing:2.4.0', 110 | 'org.grails:grails-test:2.4.0', 111 | 'junit:junit:4.11', 112 | 'org.spockframework:spock-core:0.7-groovy-2.0' 113 | ] 114 | ] 115 | resources << [ 116 | [ 117 | 'org.grails:grails-resources:2.3.7' 118 | ], 119 | [ 120 | 'org.grails:grails-resources:2.4.0' 121 | ] 122 | ] 123 | } 124 | 125 | private void hasDependency(Configuration configuration, String dependency) { 126 | def tokens = dependency.split(':') 127 | def group = tokens[0] 128 | def name = tokens[1] 129 | def version = tokens[2] 130 | def artifact = configuration.dependencies.find { 131 | it.group == group && it.name == name && it.version == version 132 | } 133 | assert artifact, "Could not find artifact $group:$name:$version" 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/eclipse/GrailsEclipseConfiguratorSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.eclipse 18 | 19 | import org.gradle.plugins.ide.eclipse.model.BuildCommand 20 | import org.grails.gradle.plugin.PluginSpec 21 | 22 | /** 23 | * Created by Jeevanandam M. (jeeva@myjeeva.com) on 7/11/14. 24 | */ 25 | class GrailsEclipseConfiguratorSpec extends PluginSpec { 26 | 27 | def setup() { 28 | project.apply plugin: 'eclipse' 29 | } 30 | 31 | def 'test eclipse project creation'() { 32 | given: 33 | def testNatures = ['org.grails.ide.eclipse.core.nature', 'org.eclipse.jdt.groovy.core.groovyNature', 34 | 'org.eclipse.jdt.core.javanature', 'org.eclipse.wst.common.project.facet.core.nature'] 35 | 36 | def testBuildCommands = [] 37 | testBuildCommands << new BuildCommand('org.eclipse.wst.common.project.facet.core.builder') 38 | testBuildCommands << new BuildCommand('org.eclipse.jdt.core.javabuilder') 39 | 40 | expect: 41 | assert project.eclipse.project.natures == testNatures 42 | assert project.eclipse.project.buildCommands == testBuildCommands 43 | } 44 | 45 | def "eclipse classpath source and test source configured"() { 46 | given: 47 | def sourceSets = project.eclipse.classpath.sourceSets.collect{ it } 48 | def sourceSet = sourceSets.get(0) 49 | def testSourceSet = sourceSets.get(1) 50 | 51 | expect: 52 | [ 53 | 'src/groovy', 'src/java', 'grails-app/controllers', 54 | 'grails-app/domain', 'grails-app/services', 'grails-app/taglib' 55 | ].each { 56 | def directory = project.file(it) 57 | assert sourceSet.allSource.srcDirs.contains(directory) 58 | } 59 | 60 | and: 61 | [ 62 | 'test/unit', 'test/integration', 'test/functional' 63 | ].each { 64 | def directory = project.file(it) 65 | assert testSourceSet.allSource.srcDirs.contains(directory) 66 | } 67 | } 68 | 69 | 70 | def 'eclipse classpath libraries configured'() { 71 | given: 72 | def dependencies = [project.configurations.bootstrap] + 73 | [project.configurations.runtime] + [project.configurations.test] 74 | 75 | expect: 76 | assert project.eclipse.classpath.plusConfigurations == dependencies 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/integ/FailureSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.integ 18 | 19 | class FailureSpec extends IntegSpec { 20 | 21 | def "handles failure"() { 22 | given: 23 | buildFile << """ 24 | grails.grailsVersion '2.0.1' 25 | """ 26 | 27 | buildFile << """ 28 | init { 29 | // jvmOptions { jvmArgs "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" } 30 | } 31 | 32 | task "package"(type: GrailsTask) { 33 | //jvmOptions { jvmArgs "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008" } 34 | } 35 | """ 36 | 37 | when: 38 | launcher("init", "-s").run().rethrowFailure() 39 | def buildConfig = file("grails-app/conf/BuildConfig.groovy") 40 | buildConfig.text = buildConfig.text.replace("dependencies {", "dependencies {\ncompile('org.spockframework:spock-grails-support:0.7-groovy-1.8')") 41 | println buildConfig.text 42 | launcher("package", "-s").run().rethrowFailure() 43 | 44 | then: 45 | task("package").state.didWork 46 | 47 | and: 48 | file("grails-app").exists() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/integ/IdeaSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.integ 18 | 19 | class IdeaSpec extends IntegSpec { 20 | 21 | def "dependencies carry over to idea module file"() { 22 | given: 23 | buildFile << """ 24 | apply plugin: 'idea' 25 | 26 | grails.grailsVersion '2.2.0' 27 | 28 | dependencies { 29 | compile 'org.codehaus.groovy:groovy-all:2.0.5' 30 | bootstrap 'org.codehaus.groovy:groovy-all:2.0.5' 31 | test 'org.grails:grails-test:2.2.0' 32 | } 33 | """ 34 | 35 | when: 36 | launcher("idea", "-s").run().rethrowFailure() 37 | 38 | then: 39 | task("ideaModule").state.didWork 40 | 41 | and: 42 | String projectName = dir.root.name 43 | File moduleFile = new File(dir.root, "${projectName}.iml") 44 | moduleFile.exists() 45 | moduleFile.text.contains("groovy-all-2.0.5.jar") 46 | moduleFile.text.contains("grails-test-2.2.0.jar") 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/integ/InitSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.integ 18 | 19 | import spock.lang.Unroll 20 | import org.grails.launcher.version.GrailsVersion 21 | 22 | @Unroll 23 | class InitSpec extends IntegSpec { 24 | 25 | def "can execute grails #initTask for #grailsVersion project"() { 26 | given: 27 | 28 | buildFile << """ 29 | grails.grailsVersion '$grailsVersion' 30 | """ 31 | 32 | if (grailsVersion.is(2, 1)) { 33 | buildFile << """ 34 | grails.groovyVersion '${grailsVersion.is(2,1,0) ? "1.8.6" : "1.8.8"}' 35 | """ 36 | } 37 | 38 | if (grailsVersion.is(2, 2)) { 39 | buildFile << """ 40 | grails.groovyVersion '2.0.5' 41 | """ 42 | } 43 | 44 | if (grailsVersion.is(2, 3)) { 45 | buildFile << """ 46 | grails.groovyVersion '2.1.9' 47 | 48 | dependencies { 49 | bootstrap 'org.grails.plugins:tomcat:7.0.50' 50 | } 51 | """ 52 | } 53 | 54 | if (grailsVersion.is(2, 4)) { 55 | buildFile << """ 56 | grails.groovyVersion '2.3.1' 57 | 58 | dependencies { 59 | bootstrap 'org.grails.plugins:tomcat:7.0.52.1' 60 | } 61 | """ 62 | } 63 | 64 | when: 65 | launcher(initTask, "-s").run().rethrowFailure() 66 | 67 | then: 68 | task(initTask).state.didWork 69 | 70 | and: 71 | file("grails-app").exists() 72 | 73 | when: 74 | file("test/integration/test/SomeTest.groovy") << """ 75 | package test 76 | 77 | import org.junit.Test 78 | 79 | class SomeTest { 80 | @Test 81 | void something() { 82 | assert true 83 | } 84 | } 85 | """ 86 | 87 | and: 88 | launcher("test", "-s").run().rethrowFailure() 89 | 90 | then: 91 | task("test").state.didWork 92 | 93 | where: 94 | versionAndTask << ["2.0.0", "2.1.0", "2.2.0", "2.3.5", "2.4.0"].collectMany { String version -> 95 | ['init', 'init-plugin'].collect { String task -> 96 | [task: task, version: GrailsVersion.parse(version)] 97 | } 98 | } 99 | grailsVersion = (GrailsVersion) versionAndTask.version 100 | initTask = (String) versionAndTask.task 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/integ/IntegSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.integ 18 | 19 | import org.gradle.GradleLauncher 20 | import org.gradle.StartParameter 21 | import org.gradle.api.Task 22 | import org.gradle.api.execution.TaskExecutionListener 23 | import org.gradle.api.tasks.TaskState 24 | import org.junit.Rule 25 | import org.junit.rules.TemporaryFolder 26 | import spock.lang.Specification 27 | 28 | abstract class IntegSpec extends Specification { 29 | @Rule final TemporaryFolder dir = new TemporaryFolder(new File('build')) 30 | 31 | static class ExecutedTask { 32 | Task task 33 | TaskState state 34 | } 35 | 36 | List executedTasks = [] 37 | 38 | GradleLauncher launcher(String... args) { 39 | StartParameter startParameter = GradleLauncher.createStartParameter(args) 40 | startParameter.setProjectDir(dir.root) 41 | GradleLauncher launcher = GradleLauncher.newInstance(startParameter) 42 | executedTasks.clear() 43 | launcher.addListener(new TaskExecutionListener() { 44 | void beforeExecute(Task task) { 45 | IntegSpec.this.executedTasks << new ExecutedTask(task: task) 46 | } 47 | 48 | void afterExecute(Task task, TaskState taskState) { 49 | IntegSpec.this.executedTasks.last().state = taskState 50 | taskState.metaClass.upToDate = taskState.skipMessage == "UP-TO-DATE" 51 | } 52 | }) 53 | launcher 54 | } 55 | 56 | File getBuildFile() { 57 | file("build.gradle") 58 | } 59 | 60 | File file(String path) { 61 | def file = new File(dir.root, path) 62 | if (!file.exists()) { 63 | file.parentFile.mkdirs() 64 | file.createNewFile() 65 | } 66 | file 67 | } 68 | 69 | ExecutedTask task(String name) { 70 | executedTasks.find { it.task.name == name } 71 | } 72 | 73 | def setup() { 74 | buildFile << """ 75 | ext { 76 | GrailsPlugin = project.class.classLoader.loadClass("org.grails.gradle.plugin.GrailsPlugin") 77 | GrailsTask = project.class.classLoader.loadClass("org.grails.gradle.plugin.tasks.GrailsTask") 78 | } 79 | version = "1.0" 80 | 81 | apply plugin: GrailsPlugin 82 | 83 | repositories { 84 | grails.central() 85 | } 86 | """ 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/internal/GrailsLaunchConfigureActionSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.internal 18 | 19 | import org.gradle.api.logging.Logger 20 | import org.gradle.process.JavaExecSpec 21 | import org.grails.launcher.context.GrailsLaunchContext 22 | import org.grails.launcher.context.SerializableGrailsLaunchContext 23 | import org.junit.Rule 24 | import org.junit.rules.TemporaryFolder 25 | import spock.lang.Specification 26 | 27 | class GrailsLaunchConfigureActionSpec extends Specification { 28 | @Rule final TemporaryFolder dir = new TemporaryFolder() 29 | 30 | File grailsHome 31 | File contextDestination 32 | GrailsLaunchContext launchContext = new SerializableGrailsLaunchContext() 33 | Logger logger = Mock() 34 | JavaExecSpec javaExecSpec = Mock() 35 | GrailsLaunchConfigureAction launchConfigureAction 36 | private File springLoaded 37 | 38 | def setup() { 39 | grailsHome = dir.newFolder() 40 | contextDestination = dir.newFile() 41 | springLoaded = dir.newFile() 42 | launchConfigureAction = new GrailsLaunchConfigureAction(launchContext, springLoaded, contextDestination) 43 | } 44 | 45 | def "grails home is passed as a system property to launcher when set"() { 46 | given: 47 | launchContext.buildDependencies = [] 48 | 49 | when: "the action is executed without grailsHome set" 50 | launchConfigureAction.execute(javaExecSpec) 51 | 52 | then: 53 | 0 * javaExecSpec.systemProperty("grails.home", _) 54 | 55 | when: "the action is executed with grailsHome set" 56 | launchContext.grailsHome = grailsHome 57 | launchConfigureAction.execute(javaExecSpec) 58 | 59 | then: 60 | 1 * javaExecSpec.systemProperty("grails.home", grailsHome.absolutePath) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/groovy/org/grails/gradle/plugin/tasks/GrailsEclipseJdtGroovyTaskSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.grails.gradle.plugin.tasks 18 | 19 | import org.gradle.api.tasks.Delete 20 | import org.grails.gradle.plugin.PluginSpec 21 | 22 | /** 23 | * Created by Jeevanandam M. (jeeva@myjeeva.com) on 7/11/14. 24 | */ 25 | class GrailsEclipseJdtGroovyTaskSpec extends PluginSpec { 26 | 27 | def setup() { 28 | project.apply plugin: 'eclipse' 29 | } 30 | 31 | def 'test eclipse jdt groovy tasks are in place'() { 32 | given: 33 | def groovyJdtTasks = ['eclipseJdtGroovy', 'cleanEclipseJdtGroovy'] 34 | 35 | expect: 36 | groovyJdtTasks.each { 37 | assert project.tasks.findByName(it) 38 | } 39 | } 40 | 41 | def 'test task type check'() { 42 | expect: 43 | project.tasks.findByName('eclipseJdtGroovy') instanceof GrailsEclipseJdtGroovyTask 44 | project.tasks.findByName('cleanEclipseJdtGroovy') instanceof Delete 45 | } 46 | 47 | def 'test eclipse jdt groovy prefs'() { 48 | when: 49 | project.tasks.getByName('eclipseJdtGroovy').execute() 50 | 51 | then: 52 | def eclipseJdtGroovy = project.tasks.findByName('eclipseJdtGroovy') 53 | def prefsFile = eclipseJdtGroovy.getOutputFile() 54 | def file = project.relativePath(prefsFile) 55 | def groovyCompilerVersion = eclipseJdtGroovy.getGroovyVersion()[0..2].replaceAll(/\./, '') 56 | 57 | assert file == '.settings/org.eclipse.jdt.groovy.core.prefs' 58 | assert prefsFile.text.contains("groovy.compiler.level=${groovyCompilerVersion}") 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 2.2.0.RC2 2 | --------------------------------------------------------------------------------