11import groovy.io.FileType
22import groovy.text.SimpleTemplateEngine
3+ import net.ltgt.gradle.errorprone.javacplugin.CheckSeverity
34
4- import java.util.regex.Matcher
5+ import java.nio.file.Files
56import java.util.regex.Pattern
67
78apply plugin : ' java-library'
89apply plugin : ' maven-publish'
910
10- apply plugin : ' net.ltgt.errorprone'
11+ apply plugin : ' net.ltgt.errorprone-javacplugin '
1112apply plugin : ' checkstyle'
1213apply plugin : ' findbugs'
1314apply plugin : ' jacoco'
@@ -48,10 +49,6 @@ dependencies {
4849 testImplementation deps. privateConstructor
4950}
5051
51- tasks. withType(JavaCompile ) {
52- options. compilerArgs + = [ ' -Xep:ParameterName:OFF' ]
53- }
54-
5552task generatePackageInfo {
5653 File generatedPackageInfoDir = file(" $buildDir /generated" )
5754
@@ -72,15 +69,11 @@ task generatePackageInfo {
7269 sourceSets. main. java. srcDirs. each {
7370 it. eachFileRecurse(FileType . FILES ) {
7471 if (it. name. endsWith(' .java' )) {
75- List<String > fileLines = it. readLines()
76-
77- if (! fileLines. isEmpty()) {
78- Matcher matcher = packagePattern. matcher(fileLines. first())
79-
80- if (matcher. matches()) {
81- packages + = matcher. group(1 )
82- }
83- }
72+ Files . lines(it. toPath())
73+ .map { line -> packagePattern. matcher(line) }
74+ .filter { matcher -> matcher. matches() }
75+ .findFirst()
76+ .ifPresent { matcher -> packages + = matcher. group(1 ) }
8477 }
8578 }
8679 }
@@ -130,10 +123,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
130123 from javadoc. destinationDir
131124}
132125
133- compileJava {
134- options. compilerArgs << " -Werror" << " -Xep:ParameterName:OFF"
135- }
136-
137126buildConfig {
138127 packageName = ' me.proxer.library'
139128 version = project. version
@@ -201,7 +190,7 @@ publishing {
201190 }
202191
203192 pom {
204- name = ' ProxerLibJava'
193+ name = ' ProxerLibJava'
205194 description = ' An Java and Android library, implementing the API of the Proxer.me website'
206195 url = ' https://github.com/proxer/ProxerLibJava'
207196
@@ -235,8 +224,21 @@ publishing {
235224 }
236225}
237226
238- test { finalizedBy jacocoTestReport }
227+ afterEvaluate {
228+ tasks. withType(JavaCompile ) {
229+ options. compilerArgs << " -Werror"
230+ options. encoding = ' UTF-8'
231+
232+ // Something seems to add a JavaCompile type task which does not has the errorprone property.
233+ if (options. hasProperty(" errorprone" )) {
234+ options. errorprone {
235+ disableWarningsInGeneratedCode = true
236+
237+ check(" ParameterName" , CheckSeverity . OFF )
238+ }
239+ }
240+ }
239241
240- gradle. projectsEvaluated {
241242 compileJava. dependsOn(generatePackageInfo)
243+ test { finalizedBy jacocoTestReport }
242244}
0 commit comments