/*
 * Copyright (C) 2021. Uber Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
plugins {
    id 'java-library'
    id 'nullaway.java-test-conventions'
}

// Use JDK 21 for this module, via a toolchain
// We must null out sourceCompatibility and targetCompatibility to use toolchains.
java.sourceCompatibility = null
java.targetCompatibility = null
java.toolchain.languageVersion.set JavaLanguageVersion.of(21)

configurations {
    // We use this configuration to expose a module path that can be
    // used to test analysis of module-info.java files.
    // See com.uber.nullaway.jdk17.NullAwayModuleInfoTests
    testModulePath
}

dependencies {
    testImplementation project(":nullaway")
    testImplementation deps.test.junit4
    testImplementation deps.test.junit5Jupiter
    testImplementation deps.test.assertJ
    testImplementation(deps.build.errorProneTestHelpers) {
        exclude group: "junit", module: "junit"
    }
    testImplementation deps.build.jsr305Annotations
    testModulePath deps.test.cfQual
}

test {
    jvmArgs += [
        // Expose a module path for tests as a JVM property.
        // Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests
        "-Dtest.module.path=${configurations.testModulePath.asPath}"
    ]
}

tasks.getByName('testJdk21').configure {
    // We don't need this task since we already run the tests on JDK 21
    onlyIf { false }
}
