xref: /aosp_15_r20/external/jspecify/gradle/integration-test.gradle (revision 2167191df2fa07300797f1ac5b707370b5f38c48)
1/*
2 * Copyright 2021 The JSpecify 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/**
18 * This build configuration generates two integration test tasks: integrationTest and integrationTestOnJava8.
19 * These tasks share the integrationTest sourceSets, which contains test cases implemented with the JUnit Jupiter API.
20 */
21
22sourceSets {
23    // The source set for integration test that depends on the generated multi-release jar file
24    integrationTest {
25        java {
26            srcDirs = ['src/integrationTest/java']
27        }
28        compileClasspath += tasks.jar.outputs.files // need to depend on not classes dirs but a jar file
29        runtimeClasspath += tasks.jar.outputs.files
30    }
31}
32
33configurations {
34    integrationTestImplementation.extendsFrom implementation
35    integrationTestRuntimeOnly.extendsFrom runtimeOnly
36}
37
38dependencies {
39    integrationTestImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
40    integrationTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
41    integrationTestRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.0'
42    errorprone "com.google.errorprone:error_prone_core:${errorproneVersion}"
43}
44
45tasks.named('compileIntegrationTestJava', JavaCompile).configure {
46    // compiled tests will run with both Java 8 and 9+
47    options.release = 8
48}
49
50def integrationTestOnJava8 = tasks.register("integrationTestOnJava8", Test)
51integrationTestOnJava8.configure {
52    group 'Verification'
53    description 'Runs the integration tests with JDK8, to verify the support for Java without jigsaw.'
54
55    classpath = sourceSets.integrationTest.runtimeClasspath
56    testClassesDirs = sourceSets.integrationTest.output.classesDirs
57    useJUnitPlatform()
58
59    javaLauncher = javaToolchains.launcherFor {
60        languageVersion = JavaLanguageVersion.of(8)
61    }
62}
63
64def integrationTest = tasks.register("integrationTest", Test)
65integrationTest.configure {
66    group 'Verification'
67    description 'Runs the integration tests with JDK9+, to verify the support for Java without jigsaw.'
68
69    classpath = sourceSets.integrationTest.runtimeClasspath
70    testClassesDirs = sourceSets.integrationTest.output.classesDirs
71    useJUnitPlatform()
72}
73
74tasks.named('check').configure {
75    dependsOn integrationTest
76    dependsOn integrationTestOnJava8
77}
78