Skip to content

Commit

Permalink
Improve dependency scopes
Browse files Browse the repository at this point in the history
- Gradle projects should use api/implementation/runtimeOnly
- Maven projects should use test scope for test engines
  • Loading branch information
marcphilipp committed May 27, 2019
1 parent 5640a98 commit 253f932
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions junit5-jupiter-extensions/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'java'
id 'java-library'
id 'eclipse' // optional (to generate Eclipse project files)
id 'idea' // optional (to generate IntelliJ IDEA project files)
}
Expand All @@ -17,10 +17,10 @@ tasks.withType(JavaCompile) {
}

dependencies {
compile("org.junit.jupiter:junit-jupiter-api:5.4.2") {
api("org.junit.jupiter:junit-jupiter-api:5.4.2") {
because 'building extensions in "main" using JUnit Jupiter API'
}
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2") {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.2") {
because 'at least one engine is needed at test runtime'
}
}
Expand Down
2 changes: 1 addition & 1 deletion junit5-jupiter-starter-gradle-groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
compile localGroovy()
implementation(localGroovy())
testImplementation('org.junit.jupiter:junit-jupiter:5.4.2')
}

Expand Down
28 changes: 14 additions & 14 deletions junit5-migration-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ Optionally, you can configure the `test` task as follows.
```groovy
test {
useJUnitPlatform {
// includeEngines 'junit-jupiter', 'junit-vintage'
// excludeEngines 'custom-engine'
// includeEngines("junit-jupiter", "junit-vintage")
// excludeEngines("custom-engine")
// includeTags 'fast'
excludeTags 'slow'
// includeTags("fast")
excludeTags("slow")
}
testLogging {
events 'passed', 'skipped', 'failed'
events("passed", "skipped", "failed")
}
}
```
Expand All @@ -53,25 +53,25 @@ Gradle will not run tests that are _tagged_ accordingly.
In order to have Gradle's `test` task run any tests at all, a `TestEngine`
implementation must be on the classpath.

To configure support for JUnit Jupiter based tests, configure a `testCompile` dependency
on the JUnit Jupiter API and a `testRuntime` dependency on the JUnit Jupiter TestEngine
implementation similar to the following.
To configure support for JUnit Jupiter based tests, configure a `testImplementation`
dependency on the `junit-jupiter` artifact. That will cause `testImplementation`
dependency on the JUnit Jupiter API and a `testRuntimeOnly` dependency on the JUnit
Jupiter TestEngine.

```groovy
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.4.2")
}
```

Gradle can also run JUnit 3 and JUnit 4 based tests as long as you
configure a `testCompile` dependency on JUnit 4 and a `testRuntime` dependency on the
JUnit Vintage TestEngine implementation similar to the following.
configure a `testImplementation` dependency on JUnit 4 and a `testRuntimeOnly` dependency
on the JUnit Vintage TestEngine implementation similar to the following.

```groovy
dependencies {
testCompile("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:5.4.2")
testImplementation("junit:junit:4.12")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.4.2")
}
```

Expand Down
6 changes: 3 additions & 3 deletions junit5-migration-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ dependencies {
// JUnit Jupiter API and TestEngine implementation
testImplementation("org.junit.jupiter:junit-jupiter")

testCompile("junit:junit:${junit4Version}")
testRuntime("org.junit.vintage:junit-vintage-engine") {
testImplementation("junit:junit:${junit4Version}")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}

testRuntime("org.junit.platform:junit-platform-launcher") {
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because 'allows tests to run from IDEs that bundle older version of launcher'
}
}
Expand Down
2 changes: 2 additions & 0 deletions junit5-migration-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down

0 comments on commit 253f932

Please sign in to comment.