@@ -1516,72 +1516,66 @@ class BeamModulePlugin implements Plugin<Project> {
15161516 project. tasks. analyzeDependencies. enabled = false
15171517 }
15181518
1519- // errorprone requires java9+ compiler. It can be used with Java8 but then sets a java9+ errorproneJavac.
1520- // However, the redirect ignores any task that forks and defines either a javaHome or an executable,
1521- // see https://github.com/tbroyer/gradle-errorprone-plugin#jdk-8-support
1522- // which means errorprone cannot run when gradle runs on Java11+ but serve `-testJavaVersion=8 -Pjava8Home` options
1523- if (! (project. findProperty(' testJavaVersion' ) == ' 8' )) {
1524- // Enable errorprone static analysis
1525- project. apply plugin : ' net.ltgt.errorprone'
1519+ // Enable errorprone static analysis
1520+ project. apply plugin : ' net.ltgt.errorprone'
15261521
1527- project. dependencies {
1528- errorprone(" com.google.errorprone:error_prone_core:$errorprone_version " )
1529- errorprone(" jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.28" )
1530- }
1531-
1532- project. configurations. errorprone { resolutionStrategy. force " com.google.errorprone:error_prone_core:$errorprone_version " }
1533-
1534- project. tasks. withType(JavaCompile ) {
1535- options. errorprone. disableWarningsInGeneratedCode = true
1536- options. errorprone. excludedPaths = ' (.*/)?(build/generated-src|build/generated.*avro-java|build/generated)/.*'
1537-
1538- // Error Prone requires some packages to be exported/opened on Java versions that support modules,
1539- // i.e. Java 9 and up. The flags became mandatory in Java 17 with JEP-403.
1540- // The -J prefix is not needed if forkOptions.javaHome is unset,
1541- // see http://github.com/gradle/gradle/issues/22747
1542- if (options. forkOptions. javaHome == null ) {
1543- options. fork = true
1544- options. forkOptions. jvmArgs + = errorProneAddModuleOpts
1545- }
1546- def disabledChecks = [
1547- // TODO(https://github.com/apache/beam/issues/20955): Enable errorprone checks
1548- " AutoValueImmutableFields" ,
1549- " ComparableType" ,
1550- " DoNotMockAutoValue" ,
1551- " EmptyBlockTag" ,
1552- " ExtendsAutoValue" ,
1553- " InlineMeSuggester" ,
1554- " InvalidBlockTag" ,
1555- " JodaConstructors" ,
1556- " MixedMutabilityReturnType" ,
1557- " PreferJavaTimeOverload" ,
1558- " Slf4jSignOnlyFormat" ,
1559- " UnrecognisedJavadocTag" ,
1560- // errorprone 3.2.0+ checks
1561- " DirectInvocationOnMock" ,
1562- " MockNotUsedInProduction" ,
1563- " NullableWildcard" ,
1564- " SuperCallToObjectMethod" ,
1565- // Intended suppressions with justifications
1566- // for encoding efficiency and backward compatibility
1567- " EnumOrdinal" ,
1568- // widely used in non-public methods
1569- " NotJavadoc" ,
1570- // return values used for assignments widely, and for backward compatibility.
1571- " NonApiType" ,
1572- // Used to test self equal
1573- " SelfAssertion" ,
1574- // Sometimes a static logger is preferred, which is the convention currently used in beam. See docs:
1575- // https://github.com/KengoTODA/findbugs-slf4j#slf4j_logger_should_be_non_static
1576- " Slf4jLoggerShouldBeNonStatic" ,
1577- // allow implicit Locale.Default
1578- " StringCaseLocaleUsage" ,
1579- // DoFn methods are executed reflectively at pipeline runtime
1580- " UnusedMethod" ,
1581- ]
1582- disabledChecks. each {
1583- options. errorprone. errorproneArgs. add(" -Xep:${ it} :OFF" )
1584- }
1522+ project. dependencies {
1523+ errorprone(" com.google.errorprone:error_prone_core:$errorprone_version " )
1524+ errorprone(" jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.28" )
1525+ }
1526+
1527+ project. configurations. errorprone { resolutionStrategy. force " com.google.errorprone:error_prone_core:$errorprone_version " }
1528+
1529+ project. tasks. withType(JavaCompile ) {
1530+ options. errorprone. disableWarningsInGeneratedCode = true
1531+ options. errorprone. excludedPaths = ' (.*/)?(build/generated-src|build/generated.*avro-java|build/generated)/.*'
1532+
1533+ // Error Prone requires some packages to be exported/opened on Java versions that support modules,
1534+ // i.e. Java 9 and up. The flags became mandatory in Java 17 with JEP-403.
1535+ // The -J prefix is not needed if forkOptions.javaHome is unset,
1536+ // see http://github.com/gradle/gradle/issues/22747
1537+ if (options. forkOptions. javaHome == null ) {
1538+ options. fork = true
1539+ options. forkOptions. jvmArgs + = errorProneAddModuleOpts
1540+ }
1541+ def disabledChecks = [
1542+ // TODO(https://github.com/apache/beam/issues/20955): Enable errorprone checks
1543+ " AutoValueImmutableFields" ,
1544+ " ComparableType" ,
1545+ " DoNotMockAutoValue" ,
1546+ " EmptyBlockTag" ,
1547+ " ExtendsAutoValue" ,
1548+ " InlineMeSuggester" ,
1549+ " InvalidBlockTag" ,
1550+ " JodaConstructors" ,
1551+ " MixedMutabilityReturnType" ,
1552+ " PreferJavaTimeOverload" ,
1553+ " Slf4jSignOnlyFormat" ,
1554+ " UnrecognisedJavadocTag" ,
1555+ // errorprone 3.2.0+ checks
1556+ " DirectInvocationOnMock" ,
1557+ " MockNotUsedInProduction" ,
1558+ " NullableWildcard" ,
1559+ " SuperCallToObjectMethod" ,
1560+ // Intended suppressions with justifications
1561+ // for encoding efficiency and backward compatibility
1562+ " EnumOrdinal" ,
1563+ // widely used in non-public methods
1564+ " NotJavadoc" ,
1565+ // return values used for assignments widely, and for backward compatibility.
1566+ " NonApiType" ,
1567+ // Used to test self equal
1568+ " SelfAssertion" ,
1569+ // Sometimes a static logger is preferred, which is the convention currently used in beam. See docs:
1570+ // https://github.com/KengoTODA/findbugs-slf4j#slf4j_logger_should_be_non_static
1571+ " Slf4jLoggerShouldBeNonStatic" ,
1572+ // allow implicit Locale.Default
1573+ " StringCaseLocaleUsage" ,
1574+ // DoFn methods are executed reflectively at pipeline runtime
1575+ " UnusedMethod" ,
1576+ ]
1577+ disabledChecks. each {
1578+ options. errorprone. errorproneArgs. add(" -Xep:${ it} :OFF" )
15851579 }
15861580 }
15871581
@@ -1624,16 +1618,19 @@ class BeamModulePlugin implements Plugin<Project> {
16241618 preserveFileTimestamps(false )
16251619 }
16261620
1621+ String testJavaVersion = project. findProperty(' testJavaVersion' )
1622+ if (! testJavaVersion && forkJavaVersion) {
1623+ testJavaVersion = forkJavaVersion
1624+ }
16271625 // if specified test java version, modify the compile and runtime versions accordingly
1628- if ([' 11' , ' 17' , ' 21' , ' 25' ]. contains(project. findProperty(' testJavaVersion' ))) {
1629- String ver = project. getProperty(' testJavaVersion' )
1630- def testJavaHome = project. getProperty(" java${ ver} Home" )
1626+ if ([' 11' , ' 17' , ' 21' , ' 25' ]. contains(testJavaVersion)) {
1627+ def testJavaHome = project. getProperty(" java${ testJavaVersion} Home" )
16311628
16321629 // redirect java compiler to specified version for compileTestJava only
16331630 project. tasks. compileTestJava {
1634- setCompileAndRuntimeJavaVersion(options. compilerArgs, ver )
1635- project. ext. setJavaVerOptions(options, ver )
1636- if (ver == ' 25' ) {
1631+ setCompileAndRuntimeJavaVersion(options. compilerArgs, testJavaVersion )
1632+ project. ext. setJavaVerOptions(options, testJavaVersion )
1633+ if (testJavaVersion == ' 25' ) {
16371634 // TODO: Upgrade errorprone version to support Java25. Currently compile crashes
16381635 // java.lang.NoSuchFieldError: Class com.sun.tools.javac.code.TypeTag does not have member field
16391636 // 'com.sun.tools.javac.code.TypeTag UNKNOWN'
0 commit comments