Resolve findBugs issue in gradle - java

Overview:
I am trying to upgrade Java and Gradle version in my project as follows:
java from 8 to 11
Gradle from 5 to 6
My project runs with no issues on the old versions but when runs on Java 11 and Gradle 6 it complains about fireBugs plugin and raises the following exception:
> Plugin with id 'findbugs' not found.
Snippet of gradle file:
buildscript {
ext {
SampleProjectVersion = '1.3.4'
}
repositories {
mavenLocal()
maven {
url1
}
}
dependencies {
classpath(sample lib 1)
classpath(sample lib 2)
}
apply plugin: 'findbugs'
...
I would appreciate if you could share your thoughts with me as I couldn't find any proper solution for that.

From the Gradle web site (Upgrading your build from Gradle 5.x to 6.0):
The FindBugs plugin has been removed
The deprecated FindBugs plugin has been removed. As an alternative,
you can use the SpotBugs plugin from the Gradle Plugin Portal.
https://docs.gradle.org/current/userguide/upgrading_version_5.html

You can use the SpotBugs plugin. Try my snippet of gradle file
buildscript {
ext {
SampleProjectVersion = '1.3.4'
}
repositories {
mavenLocal()
maven {
url1
}
}
dependencies {
classpath(sample lib 1)
classpath(sample lib 2)
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:2.0.0"
}
apply plugin: "com.github.spotbugs"
tasks.withType(com.github.spotbugs.SpotBugsTask) {
spotbugsMain.enabled = true
spotbugsTest.enabled = true
reports {
xml.enabled = false
html.enabled = true
}
}
...

Related

How to disable downloading of sources.jar and javadoc.jar

I have configured as follows in app/build.gradle, but it not works. Can someone tell me how to disable download of sources and javadoc? The version of AndroidStudio is 4.0, and the grade plugin version is also 4.0.0
idea {
module {
downloadJavadoc = false
downloadSources = false
}
}
Add idea plugin to gradle file like this:
plugins {
...
id 'idea'
}

Gradle: 'compile' cannot be applied

Today I started a new JDK 11 project with Gradle 5.0 (using the Gradle Wrapper) and created a basic build script:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.6.0'
}
}
plugins {
id 'java'
}
apply plugin: 'com.google.osdetector'
ext.platform = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os
version = '0.1.0'
repositories {
mavenCentral()
}
dependencies {
compile "org.openjfx:javafx-graphics:11:$platform"
}
This - rather basic - build script results in the error
'compile' in 'org.gradle.api.artifacts.dsl.DependencyHandler' cannot
be applied to '(groovy.lang.GString)'
Is that a JDK 11, a Gradle 5.0 or a user error? I've never seen that before.
According to JetBrains support this is a known bug and will be fixed in 2018.3.1.
See: https://youtrack.jetbrains.com/issue/IDEA-203393
The messages only appear within IntelliJ using Gradle 5.0 (e.g. 2018.3).
The build works fine, started from console or from IntelliJ.

Android Studio 3.0 Canary 2: Failed to apply plugin, when using gradle 3.0.0-alpha2

I just updated to using Android Studio 3.0 Canary 2. Upon opening my project Android Studio suggested I update the gradle version to 3.0.0-alpha2. My goal is to use the "Enable advanced profiling" Run Configuration so I can run a realtime memory-analysis. However the instant my gradle version was updated, my project fails to build. I followed the update instructions here.
The only changes made were to my top-level build.gradle file and the gradle-wrapper.properties file.
My top-level build.gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
classpath 'com.github.Archinamon:GradleAspectJ-Android:2.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.5.0'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://repo.adobe.com/nexus/content/repositories/releases/' }
maven { url 'http://maven.localytics.com/public' }
}
}
And I updated the gradle-wrapper.properties distributionURL to:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
The error I get is:
Failed to apply plugin [id'com.archinamon.aspectJ']
And here is the offending part of my app-level build.gradle file:
import java.text.SimpleDateFormat
apply plugin: 'com.android.application'
apply plugin: 'com.archinamon.aspectj'
aspectj {
includeAspectsFromJar 'Android_MTAgent'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
....
}
So the problem seems to be with the aspectJ plugin. If I remove the plugin for aspectJ and the related aspectJ block (both shown above) then it compiles (I get a dimen error then though, but I already saw that mentioned elsewhere, so I guess that can be solved.)
I'd appreciate any pointers/ideas in regard to the above issue.
Change your project build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
}
and update your Archinamon classpath reference in the same build.gradle file to:
classpath 'com.github.Archinamon:GradleAspectJ-Android:3.0.2'

How to compile project with Google Checkstyle rules with gradle?

I am trying to use Google checkstyle configuration (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml) but I am constantly getting an error on gradle check:
Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
I used Gradle to build the project. Below is my gradle.build.
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'checkstyle'
sourceCompatibility = 1.8
version = '1.0'
checkstyle {
toolVersion = "6.3"
}
task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
jar {
manifest {
attributes 'Implementation-Title': 'xyz',
'Implementation-Version': 0.01
}
}
repositories {
mavenCentral()
}
dependencies {
compile (
['org.apache.logging.log4j:log4j-api:2.2'],
['org.apache.logging.log4j:log4j-core:2.2']
)
testCompile(
['junit:junit:4.11'],
['org.mockito:mockito-core:1.+']
)
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
Also, when I try to add XML config file to Checkstyle plugin in IDEA I get similar error but with a stack trace:
org.infernus.idea.checkstyle.exception.CheckStylePluginException: <html><b>The CheckStyle rules file could not be loaded.</b><br>cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock</html>
at org.infernus.idea.checkstyle.checker.CheckerFactory.blacklistAndShowMessage(CheckerFactory.java:234)
at org.infernus.idea.checkstyle.checker.CheckerFactory.createChecker(CheckerFactory.java:188)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getOrCreateCachedChecker(CheckerFactory.java:98)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:73)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:41)
I cannot figure out what am I doing wrong. Any help would be appreciated.
Gradle version: 2.2
You can add this configuration into your build.gradle file:
configurations {
checkstyleOverride
}
dependencies {
checkstyleOverride('com.puppycrawl.tools:checkstyle:6.11.2')
}
tasks.withType(Checkstyle) {
checkstyleClasspath = project.configurations.checkstyleOverride
}
Enjoy!
The problem lies in the fact that com.puppycrawl.tools.checkstyle.checks.blocks.EmptyCatchBlockCheck was indeed added to checkstyle but for version 6.4-SNAPSHOT. As it can be seen in checkstyle repository (pom.xml history) version 6.4-SNAPSHOT was introduced on the 02.02.2015 and EmptyCatchBlockCheck class was created on 18.02.2015.
Gradle still uses version 6.3 as in the following log extract:
:checkstyleMain
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.3/checkstyle-6.3.pom
So there's simply no class You'd like to use.
According to the docs checkstyle classpath can be specified with checkstyleClasspath property - you can try to set it up manually.
I've also prepared a demo with 6.4-SNAPSHOT version, it can be found here. Checkstyle jar was built with mvn clean package with source taken from this repo.
Here is an approach that works with the (currently) latest versions of Gradle & Checkstyle (Gradle 6.1.1 & Checkstyle 8.29):
plugins {
id 'java'
id 'checkstyle'
}
configurations {
checkstyleConfig
}
dependencies {
checkstyleConfig("com.puppycrawl.tools:checkstyle:8.29") { transitive = false }
}
checkstyle {
toolVersion '8.29'
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
}
Note that the Checkstyle dependency excludes transitive dependencies, otherwise the resources.text.fromArchiveEntry will fail since multiple JAR files will be present, and it will be unable to select a single one.

Gradle eclipse using incorrect version for dependencies

I'm migrating a project to gradle to resolve dependencies, generate the eclipse project and build the project and I'm with a problem with the version of some dependencies on eclipse project. Here's the build.gradle of the project. It's an EAR with sub-projects.
apply plugin: 'ear'
def eclipseJbossName = 'org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/JBoss 6.x Runtime'
def defaultEarConfig = rootDir.getAbsolutePath() + '/ear.gradle'
allprojects {
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
eclipse {
classpath {
containers eclipseJbossName
}
}
repositories {
maven {
name = "mvnrepository"
url = "http://mvnrepository.com/"
}
mavenCentral()
maven {
name = 'jboss'
url = 'http://repository.jboss.org/nexus/content/groups/public/'
}
}
}
subprojects {
configurations {
provided
}
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceSets {
main {
compileClasspath += configurations.provided
compileClasspath += configurations.compile
compileClasspath += configurations.runtime
}
}
}
dependencies {
deploy (project(path: 'anEJB')) {
transitive = false
}
deploy (project(path: 'anotherEJB')) {
transitive = false
}
deploy (project(path: 'aWAR', configuration: 'archives')) {
transitive = false
}
earlib ('commons-beanutils:commons-beanutils:1.6') {
transitive = false
}
//lots of other dependencies and all with transitive=false
}
//configuration of my subprojects
When I call gradle ear it builds and generate my artifact correctly. In the lib directory inside the root of the EAR there's all my earlibs with its correct versions. When I call gradle cleanEclipse eclipse it generates my project right, but when I see the build path inside eclipse it is using an incorrect version for commons beanutils. It is using the version 1.8. This is not happening for all my dependencies, but there are others with this problem. I've put all to not resolve the transitive dependencies.
You can click the project in Eclipse with right mouse button, then click properties. And select "Java Build Path" then click "Libraries" tab. Finally remove all jars besides "Gradle Dependencies" & "JRE System Libraries".
Done. Try it.

Categories

Resources