HHH-16896 Pass stubs location with a CommandLineArgumentProvider

This commit is contained in:
Jerome Prinet 2023-07-04 10:53:27 +02:00 committed by Jan Schatteman
parent 135871dbd9
commit 772cd5e315
1 changed files with 22 additions and 3 deletions

View File

@ -518,14 +518,33 @@ task nonFatalCheckstyle(type:Checkstyle) {
configFile = rootProject.file( 'shared/config/checkstyle/checkstyle-non-fatal.xml' ) configFile = rootProject.file( 'shared/config/checkstyle/checkstyle-non-fatal.xml' )
} }
class CompilerStubsArgumentProvider implements CommandLineArgumentProvider {
@InputDirectory
@PathSensitive(PathSensitivity.NONE)
File stubsDir
@Override
Iterable<String> asArguments() {
{ return ["-Astubs=${stubsDir}"]}
}
}
tasks.withType(JavaCompile).configureEach { task ->
// stubs argument needs to be passed as an absolute path, JavaCompile uses the Worker API which changes the current
// working directory and prevents from using a relative path to locate a project file.
// Using a CommandLineArgumentProvider allows build cache hits when the build cache is relocated.
task.options.compilerArgumentProviders.add(new CompilerStubsArgumentProvider(stubsDir: new File(project.rootDir, "checkerstubs")))
}
checkerFramework { checkerFramework {
checkers = [ checkers = [
'org.checkerframework.checker.nullness.NullnessChecker' 'org.checkerframework.checker.nullness.NullnessChecker'
] ]
extraJavacArgs = [ extraJavacArgs = [
'-AsuppressWarnings=initialization', '-AsuppressWarnings=initialization',
"-Astubs=${project.rootDir}/checkerstubs", // stubs is passed directly through options.compilerArgumentProviders
'-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.(profile|transaction)|(action|context|bytecode)\\.spi)\\.' '-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.(profile|transaction)|(action|context|bytecode)\\.spi)\\.'
] ]
} }