This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from ysb33r/development
FIXED #49 FIXED #51 FIXED #53 FIXED #55 FIXED #56 FIXED #57 FIXED #59 FIXED #60 FIXED #61 FIXED #62 FIXED #63 FIXED #67
- Loading branch information
Showing
68 changed files
with
1,147 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
compatibility/src/nonLegacyOnlyGradleTest/gradleRunnerProject/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This buildscript block is not required in normal build scripts. It is purely here to get the classpath | ||
// correct during compatibility testing. | ||
buildscript { | ||
dependencies { | ||
classpath gradleTestKit() | ||
} | ||
} | ||
|
||
apply plugin : 'org.ysb33r.gradlerunner' | ||
|
||
gradleRunner { | ||
step 'gradleTasks', 'tasks', '--all' | ||
} | ||
|
||
task runGradleTest { | ||
dependsOn gradleRunner | ||
} |
5 changes: 5 additions & 0 deletions
5
compatibility/src/nonLegacyOnlyGradleTest/multiPluginProject/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// See https://github.com/ysb33r/gradleTest/issues/51 | ||
|
||
task runGradleTest { | ||
dependsOn ':pluginA:runGradleTest' | ||
} |
5 changes: 5 additions & 0 deletions
5
compatibility/src/nonLegacyOnlyGradleTest/multiPluginProject/myLib/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apply plugin : 'groovy' | ||
|
||
dependencies { | ||
compile localGroovy() | ||
} |
5 changes: 5 additions & 0 deletions
5
...onLegacyOnlyGradleTest/multiPluginProject/myLib/src/main/groovy/multiproject/MyLib.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package multiproject | ||
|
||
class MyLib { | ||
final static String NAME = 'MyLib' | ||
} |
30 changes: 30 additions & 0 deletions
30
compatibility/src/nonLegacyOnlyGradleTest/multiPluginProject/pluginA/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apply plugin : 'groovy' | ||
apply plugin : 'org.ysb33r.gradletest' | ||
|
||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
compile project(':myLib') | ||
compile localGroovy() | ||
compile gradleApi() | ||
} | ||
|
||
gradleTest { | ||
versions '2.13','3.0' | ||
} | ||
|
||
// This is nice for debugging, but can only be done on later versions | ||
if(GradleVersion.current() > GradleVersion.version('2.13')) { | ||
gradleTest { | ||
beforeTest { | ||
println '-'.multiply(60) | ||
println "| [${project.name}] ${it.name}" | ||
println "| ${configurations.gradleTestCompile.asPath}" | ||
println '-'.multiply(60) | ||
} | ||
} | ||
} | ||
|
||
task runGradleTest( dependsOn : ['assemble','gradleTest'] ) |
5 changes: 5 additions & 0 deletions
5
...nLegacyOnlyGradleTest/multiPluginProject/pluginA/src/gradleTest/testMyPlugin/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apply plugin : multiproject.MyLibPlugin | ||
|
||
task runGradleTest { | ||
dependsOn myLibRunner | ||
} |
14 changes: 14 additions & 0 deletions
14
...OnlyGradleTest/multiPluginProject/pluginA/src/main/groovy/multiproject/MyLibPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package multiproject | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
class MyLibPlugin implements Plugin<Project> { | ||
void apply(Project project) { | ||
project.tasks.create ('myLibRunner') { | ||
doLast { | ||
println MyLib.NAME | ||
} | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
compatibility/src/nonLegacyOnlyGradleTest/multiPluginProject/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include 'myLib' | ||
include 'pluginA' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
= Alternative Approaches to GradleTest | ||
|
||
== Gradle TestKit | ||
|
||
`GradleTestKit` is the core API that ships with Gradle since Gradle 2.6. which is meant for plugin developers to test compatibility across Gradle versions. Easrly versions could only tests against the same version of Gradle that was running, but it has been enhanced over different Gradle releases. Today it is powereful allowing multiple versions to be tested and a number of different environments to be set up. | ||
|
||
It is also a core compoenent of `GradleTest` when the version of Gradle is 2.13 or later. (When the current build version is older `GradleTest` falls back to legacy mode, simply because the `GradleTestKit` API either is non-existent or not mature enough. | ||
|
||
`GradleTestKit` works well for integration testing when writing plugins if a select small group of Gradle versions are used or even if it only targets the current Gradle version. In this way one can quickly determine issues in a plugin which cannot be discovered via normal testing. `GradleTest` used `GradleTestKit` directly for its integration tests for exactly this reason. | ||
|
||
Testing multiple versions of Gradle with GradleTestKit soon bcomes a burden for developers as the API differs and classpath setups can be tricky. Older versions of Gradle give the most issues. In addition `GradleTestKit` is essentially a library it focuses on the developer rather than the build script user. | ||
|
||
In this regard `GradleTest` steps in as it allow tests to be written as if a normal buildscript would be written. it also manages differences (or non-existance) in API from Gradle 2.0 onwards in a completely transparent way to the plugin author. | ||
|
||
Overall the approach should be to write integration tests with `GradleTestKit` using a limited or even just one Gradle version. This is then complimented by some `GradleTest` scripts to test a wider range of Gradle versions. | ||
|
||
== Stutter | ||
|
||
https://github.com/ajoberstar/gradle-stutter[Stutter] is another library by https://github.com/ajoberstar[Andy Oberstar] to aid with plugin development. It focuses on the cases where you might have to run the same tests against all supported versions, but don't want to deal with making each test loop over those versions (or `@Unroll` with a `where` block in Spock). `Stutter` generates one task per supported version for you and runs the full set of tests against it. | ||
|
||
It definitely removes some of the complexity of setting up the `GradleTestKit` environment, but beware that it works from Gradle 2.13 onwards. The latter is not a restriction, but essentialy the same reason why `GradleTest` reverts to legacy mode if the build version of Gradle is older than 2.13: a lack of maturity in the `GradleTestKit` API in those releases. | ||
|
||
It adds a `compatTest` source set, which will not clash with the `gradleTest` source set from `GradleTest`. | ||
|
||
`Stutter` is essentialy developer-centric whereas `GradleTest` is script author-centric. This distinction is important as it clarifies different levels of validation: | ||
|
||
- If you want to create good samples and make sure they build, GradleTest is a clear win. Not having to write the extra test code (or touch the TestKit API) is a great benefit. | ||
- If you need to validate what the build did, you are back in `GradleTestKit` land and then `Stutter` will make it easier for you. | ||
|
||
It can be an easy way to manage some more complex plugin integration tests. There is no reason to not use it alongside `GradleTest` as part of plugin development. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
== Command-line Awareness | ||
|
||
GradleTest is aware of certain command-line parameters and will pass them on to running tests. | ||
|
||
* `--rerun-tasks` - All tests will be re-run even if they were previsouly successful. | ||
* `--offline` - No dependency checks will be performed and if plugins implements any offline behaviour this will automatically be enabled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
= GradleRunner (Gradle 2.14.1+) | ||
|
||
The `org.ysb33r.gradlerunner` plugin adds a default task called `gradleRunner` which is of type `GradleRunnerSteps`. This task allows people to run specific Gradle steps interlevaed via other actions such as copying files. This is specifically useful for people who need to document development steps where Gradle is involved. | ||
|
||
Steps are added via the `step` keyword. Each step has a name which can later be used to extract information after execution. | ||
|
||
[source,groovy] | ||
---- | ||
gradleRunner { | ||
step 'a simple closure', { // <1> | ||
new File(workingDir,'build.gradle').text = '/* empty build file */' | ||
new File(reportsDir,'foo.txt').txt = 'output to report directory' // <2> | ||
} | ||
step 'running gradle', 'tasks', '--all' // <3> | ||
failingStep 'this gradle will fail', 'non-existing-task' // <4> | ||
} | ||
---- | ||
<1> A step can be a closure or an `Action`. | ||
<2> Every step will have an unique directory for dropping files, | ||
<3> A step can be a Gradle execution. Supply all command-line parameters after the name. A Gradle execution will drop `out.txt` and `err.txt` in the report directory. | ||
<4> A step can also be a Gradle execution that is known to fail. | ||
|
||
After execution use `gradleRunner.getStepReportDir(STEP_NAME)` to obtain the reporting directory for a step. |
Oops, something went wrong.