Skip to content

Commit

Permalink
Fixes #675. Add ratpack.baseDir to configure base dir for Gradle.
Browse files Browse the repository at this point in the history
Defaults to `src/ratpack`
  • Loading branch information
johnrengelman committed Jun 12, 2015
1 parent b3e6baf commit 9b1be3d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
Expand Up @@ -24,6 +24,6 @@ class RatpackBasePlugin implements Plugin<Project> {
@Override
void apply(Project project) {

project.extensions.create("ratpack", RatpackDependencies, project.dependencies)
project.extensions.create("ratpack", RatpackExtension, project)
}
}
Expand Up @@ -16,18 +16,22 @@

package ratpack.gradle

import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.dsl.DependencyHandler

class RatpackDependencies {
class RatpackExtension {

public static final String GROUP = "io.ratpack"
private final version = getClass().classLoader.getResource("ratpack/ratpack-version.txt").text.trim()

private final DependencyHandler dependencies

RatpackDependencies(DependencyHandler dependencies) {
this.dependencies = dependencies
File baseDir

RatpackExtension(Project project) {
this.dependencies = project.dependencies
baseDir = project.file('src/ratpack')
}

Dependency getCore() {
Expand Down
Expand Up @@ -29,11 +29,11 @@ class RatpackGroovyPlugin implements Plugin<Project> {

project.mainClassName = "ratpack.groovy.GroovyRatpackMain"

def ratpackDependencies = new RatpackDependencies(project.dependencies)
def ratpackExtension = project.extensions.getByType(RatpackExtension)

project.dependencies {
compile ratpackDependencies.groovy
testCompile ratpackDependencies.groovyTest
compile ratpackExtension.groovy
testCompile ratpackExtension.groovyTest
}
}

Expand Down
Expand Up @@ -47,11 +47,11 @@ class RatpackPlugin implements Plugin<Project> {

def ratpackApp = new SpringloadedUtil(project, project.configurations['springloaded'])

RatpackDependencies ratpackDependencies = project.extensions.findByType(RatpackDependencies)
RatpackExtension ratpackExtension = project.extensions.findByType(RatpackExtension)

project.dependencies {
compile ratpackDependencies.core
testCompile ratpackDependencies.test
compile ratpackExtension.core
testCompile ratpackExtension.test
}

def configureRun = project.task("configureRun")
Expand All @@ -61,7 +61,7 @@ class RatpackPlugin implements Plugin<Project> {
classpath ratpackApp.springloadedClasspath
jvmArgs ratpackApp.springloadedJvmArgs
systemProperty "ratpack.development", true
systemProperty "ratpack.baseDir.override", project.file("src/ratpack").absolutePath
systemProperty "ratpack.baseDir.override", ratpackExtension.baseDir.absolutePath
}
}

Expand All @@ -71,16 +71,18 @@ class RatpackPlugin implements Plugin<Project> {

SourceSetContainer sourceSets = project.sourceSets
def mainSourceSet = sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]
mainSourceSet.resources.srcDir(project.file("src/ratpack"))
mainSourceSet.resources.srcDir {
ratpackExtension.baseDir
}

def prepareBaseDirTask = project.tasks.create("prepareBaseDir")
prepareBaseDirTask.with {
group = "Ratpack"
description = "Lifecycle task for all tasks that contribute content to 'src/ratpack' (add dependencies to this task)"
description = "Lifecycle task for all tasks that contribute content to Ratpack base directory (default: 'src/ratpack') (add dependencies to this task)"
}

def appPluginConvention = project.getConvention().getPlugin(ApplicationPluginConvention)
appPluginConvention.applicationDistribution.from("src/ratpack") {
appPluginConvention.applicationDistribution.from({ratpackExtension.baseDir}) {
into "app"
}

Expand Down
36 changes: 29 additions & 7 deletions ratpack-manual/src/content/chapters/60-gradle.md
Expand Up @@ -142,25 +142,47 @@ You can now have the build generate the fat-jar, by running…

## The base dir

The `src/ratpack` directory in the Gradle project effectively becomes the base dir of your Ratpack application.
By default, the plugin configures the base dir of your Ratpack application to be the `src/ratpack` directory in the Gradle project.
That is, these are the files that are visible to your application (e.g. static files to serve).

The base dir can by configured by setting the `ratpack.baseDir` property in the Gradle build.

```language-groovy gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.ratpack:ratpack-gradle:@ratpack-version@"
}
}
apply plugin: "io.ratpack.ratpack-groovy"
repositories {
jcenter()
}
ratpack.baseDir = file('assets/ratpack')
```

This directory will be included in the distribution built by the `'application'` plugin as the `app` directory.
This directory will be added to the classpath when starting the application, and will also be the JVM working directory.

See [Launching](launching.html) for more information.

### The 'ratpack.groovy' script

The `'ratpack-groovy'` plugin expects the main application definition to be located at either `src/ratpack/ratpack.groovy` or `src/ratpack/Ratpack.groovy`.
The `'ratpack-groovy'` plugin expects the main application definition to be located at either `<ratpackBaseDir>/ratpack.groovy` or `<ratpackBaseDir>/Ratpack.groovy`.
By default, it will look in `src/ratpack/ratpack.groovy` and `src/ratpack/Ratpack.groovy` respectively.
This file should *not* go in to `src/main/groovy`.

See [Groovy](groovy.html) for more information about the contents of this file.

### Generated files

Your build may generate files to be served or otherwise used at runtime.
The best approach is to have the tasks that generate these files generate into a subdirectory of `src/ratpack`.
The best approach is to have the tasks that generate these files generate into a subdirectory of the `<ratpackBaseDir>` (by default `src/ratpack`).
The Ratpack Gradle plugins add a special task named `'prepareBaseDir`' that you should make depend on your generation task.

```language-groovy gradle
Expand All @@ -181,7 +203,7 @@ repositories {
task generateDocs(type: Copy) {
from "src/documentation"
into "src/ratpack/documentation"
into "${ratpack.baseDir}/documentation"
expand version: project.version
}
Expand All @@ -201,7 +223,7 @@ Making `'prepareBaseDir'` depend on your generation task ensures that it is invo

The `'application'` plugin provides the `'run'` task for starting the Ratpack application.
This is a task of the core Gradle [`JavaExec`](http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.JavaExec.html) type.
The `'ratpack-java'` plugin configures this `'run'` task to start the process in `src/ratpack` and to launch with the system property `'ratpack.development'` set to `true` (which enables development time code reloading).
The `'ratpack-java'` plugin configures this `'run'` task to start the process in `<ratpackBaseDir>` (default `src/ratpack`) and to launch with the system property `'ratpack.development'` set to `true` (which enables development time code reloading).

If you wish to set extra system properties for development time execution, you can configure this task…

Expand Down Expand Up @@ -305,7 +327,7 @@ In the second, run the following after making a code change…

If you'd like to have Gradle automatically compile changes as they happen, you can use the [Gradle Watch](https://github.com/bluepapa32/gradle-watch-plugin) plugin.

Note: You do not need SpringLoaded support for reloading changes to the `src/ratpack/Ratpack.groovy` file when using `'ratpack-groovy'`, nor do you need to have Gradle recompile the code.
Note: You do not need SpringLoaded support for reloading changes to the `<ratpackBaseDir>/Ratpack.groovy` file when using `'ratpack-groovy'`, nor do you need to have Gradle recompile the code.
The reloading of this file is handled at runtime in reloadable mode.

## IntelliJ IDEA support
Expand Down Expand Up @@ -347,5 +369,5 @@ Once the project is opened, you will see a “Run Configuration” named “Ratp

If you have configured your build to use SpringLoaded, it will also be used by IDEA.
However, IDEA will not automatically recompile code while there is an active run configuration.
This means that after making a code change (to anything other than `src/ratpack/Ratpack.groovy`) you need to click “Make Project” in the “Build” menu (or use the corresponding key shortcut).
This means that after making a code change (to anything other than `<ratpackBaseDir>/Ratpack.groovy`) you need to click “Make Project” in the “Build” menu (or use the corresponding key shortcut).

0 comments on commit 9b1be3d

Please sign in to comment.