SonarQube Gradle Plugin warnings: "Class not found: org.joda.convert" [duplicate] - java

This question already has an answer here:
Sonarqube Analysis org.joda.convert ERROR
(1 answer)
Closed 6 years ago.
While running the SonarQube Gradle plugin on our project, during the Java Main Files AST scan, we're getting a number of warnings about joda-convert:
[WARN] [org.sonarqube.gradle.SonarQubeTask] Class not found: org.joda.convert.FromString
[WARN] [org.sonarqube.gradle.SonarQubeTask] Class not found: org.joda.convert.ToString
I've tried several ways of pulling in org.joda:joda-convert:1.8 and none of them have solved the problem. How can we figure out why this dependency is not being found?
Note: we're using Java JDK 1.8, Gradle 2.11, and SonarQube 5.3.
EDIT: this is the relevant snippet from build.gradle. I've tried joda-convert versions 1.7, 1.8, and 1.8.1 with no success.
buildscript {
repositories {
maven {
url "http://artifactory:7980/artifactory/libs-release"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2"
classpath 'org.joda:joda-convert:1.7'
}
}
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.projectName", "Project"
property "sonar.projectKey", "local.project"
}
}

Joda time has two packages, joda-time and Joda-Convert. The annotations you are not able to find are in the Joda-Convert package, not [joda-time].
These errors are just low-severity warnings and should not actually affect your issues with using joda-time.
However, upon a second read-through of your question, it looks like you've already realized this and have included the dependency in your .gradle file. This suggests to me that most likely it's a configuration syntax issue with your .gradle file. If the first paragraph doesn't solve your issue, then please edit your question to include a .gradle snippet about how you've tried to include this dependency to fix the problem. Please note that Joda-time has Joda-convert as an optional dependency in its Maven POM and that could be confusing Gradle.
Also please include the versions of both joda-time and joda-convert you are attempting to use when you edit your question.

Related

How can I stop Gradle deleting .jars from my project's module path?

I'm trying to develop a Gradle project which involves JavaFX.
Specs: Linux Mint 18.3, Java 11, Eclipse 2019-06, JavaFX: either 13 or 11...
A couple of useful answers to questions have helped me over the past hours: this one tells me (with useful clonable example) how to configure things, at least using a Java file to hold my project's main class (in fact I ultimately want to write all my code in Groovy ideally), in order to overcome the error "JavaFX runtime components are missing, and are required to run this application".
But Eclipse doesn't like it when you add the final step: the file module-info.java. At this point I have to confess I know nothing whatsoever about Eclipse "modules": only that this unknown aspect of the IDE has occasionally caused me frustrating headaches in the past. Probably time to read up on it now.
I should also clarify that at this point the Gradle tasks build and installdist (or assemble) work fine at the CLI. I am only concerned about getting rid of these horrid Eclipse white-cross-in-red-box error marks:
in module-info.java: "javafx.controls cannot be resolved to a module"
in Main.java: all the JavaFX classes have this next to them "Application [etc.] cannot be resolved to a type", and all the imports have "The type javafx.scene.Scene [etc.] is not accessible"
This answer says to download the JavaFX-JDK and then add various .jars from it to your project's module path. I did that: the horrid errors all disappeared!
Next time I did a Gradle - Refresh they all came back. I checked module path: all these .jar files had been removed. How can I stop the Gradle-Eclipse functionality messing with my configured module path?
edit
re the comment by Slaw: yes, already using
id 'org.openjfx.javafxplugin' version '0.0.8'
... my build.gradle javafx block looks like this:
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
(NB I have now tried experimenting by adding 'javafx.graphics' and 'javafx.base' to the above.)
The issue is that Gradle - Refresh nevertheless causes the above "disappearing .jars" phenomenon.
I tried adding this to my plugins block:
id 'org.javamodularity.moduleplugin' version '1.6.0' apply true/false // NB tried both
... no go: Gradle - Refresh leads to an incomprehensible (to me) error:
An exception occurred applying plugin request [id: 'org.openjfx.javafxplugin', version: '0.0.8']
> Failed to apply plugin [id 'org.openjfx.javafxplugin']
> Could not create task ':configJavafxRun'.
> Could not create task of type 'ExecTask'.
> Could not generate a decorated class for class org.openjfx.gradle.tasks.ExecTask.
> org/javamodularity/moduleplugin/tasks/ModuleOptions

Gradle - Class not loaded : org.docx4j.jaxb.Context

I had a maven project with old docx4j dependencies, and I wanted to update to java 9. During the update I changed my project from maven to gradle.
So now I have a gradle project in IntelliJ with this dependencies:
dependencies {
implementation('commons-io:commons-io:2.6')
implementation('javax.xml.bind:jaxb-api:2.4.0-b180725.047')
implementation('org.docx4j:docx4j:6.0.1')
implementation('org.docx4j:docx4j-ImportXHTML:6.0.1')
implementation('org.docx4j:docx4j-export-fo:6.0.1')
testImplementation('junit:junit:4.12')
}
The build is working, but if I want to open a .docx file, with Docx4J.load(...) or WordprocessingMLPackage.load(...) it throws a RuntimeException.
In debug mode I can see this message: Class not loaded : org.docx4j.jaxb.Context
This Context.java file has a static code block like this:
static {
...
}
I think it's gradle specific error, because I created a new maven project with the same code and dependencies as the gradle project, and it works.
Is there any solution for this, or should I use maven in the future too?
There is a Gradle-specific answer at https://stackoverflow.com/a/51235096/1031689
Or to "add module" instead, see for example:
https://www.concretepage.com/questions/531
https://github.com/IntershopCommunicationsAG/jaxb-gradle-plugin/issues/11
Or mac java 9 gradle ClassNotFoundException: javax.xml.bind.JAXBElement when building

custom library from maven not able to download for different version

I have a custom library uploaded to bintray maven with version 1.0.0
To download it for any project i have used the following code
repositories {
maven {
url "http://dl.bintray.com/<org or user name>/<repo-name>"
}
}
And inside my app level build.gradle i have added the dependency
dependencies {
.....
compile 'my-group-id:artifactId:versionId'
.....
}
Recently i upgraded the versionId to 1.0.2 and it doesn't compile. For version 1.0.0 it compiles fine.
Heres the error i get
Error: Could not find sdk.jar (com.appunfold:sdk:1.0.2).
Searched in the following locations:
http://dl.bintray.com/appunfold/android/com/appunfold/sdk/1.0.2/sdk-1.0.2.jar
I checked the files inside 1.0.2. It contains sdk-1.0.2.aar (not sdk-1.0.2.jar)and compared it with the files inside 1.0.0. It contains the same with the version 1.0.0 i,e sdk-1.0.0.aar.
I couldn't find the reason why it is not able to download for a different version. Anybody faced the same issue?
Found the solution after a deep few hours of research.
I think Android Studio by default searches for jar files. But since in my case only aar files are available i had to specify one more parameter (#aar) while compiling the dependency.
It looks like this
dependencies {
.....
compile 'my-group-id:artifactId:versionId:#aar'
.....
}

Cannot find symbol class "Generated" for Dagger 2

I just started doing dependency injection using Dagger 2. When I spun up my modules, components and tried to build my application, gradle threw the error
Error:(4, 24) error: cannot find symbol class Generated
I dug into it and found that the error is in one of the classes Dagger generates to do DI. The particular class that's missing was javax.annotation.Generated and the line throwing the error is the line that anntotates a Dagger generated class as #Generated("dagger.internal.codegen.ComponentProcessor")
This question helped in finding the solution which is to add the javax package as a dependency by adding the line compile 'org.glassfish:javax.annotation:10.0-b28' to my gradle build file. This led to a successful build.
My question is, why is that not added as a transitive dependency for Dagger or why hasn't anyone else faced this particular issue (I assume so, since I couldn't find any question here regarding this?
TL;DR use Dagger >= 2.1
Alex is right, but it's better to add JSR250 dependency instead of GlassFish
provided 'javax.annotation:jsr250-api:1.0'
or for the latest gradle plugin:
compileOnly 'javax.annotation:jsr250-api:1.0'
Read this for more info: https://github.com/google/dagger/issues/95
Basically, the solution is to do what you've already done which is include the glassfish javax annotation library.
This happens if your JAVA_HOME points to JAVA version 9 or 10. Switching JAVA_HOME to Java 8 fixes the problem and you will not need that extra dependency.
I downgraded my JVM to Java 8 and running gradle build was successful in my Android application using Dagger 2.
The right answer today is to use a version of dagger which is greater than 2.1 (because of the fix mentioned by #tomrozb is integrated in 2.1)

How can you override an existing Gradle plugin from a local repository?

I am building an application using Gradle, JDK 8, Java FX, and Test FX. I need to be on JDK 8 for our application to work on all platforms with our tech stack. My problem is that I am unable to get code coverage into our build. I found this link...
https://github.com/jacoco/jacoco/issues/74
...and using the Jacoco preview build at the top, I was able to replace my intellij JARs and successfully run my tests and get the coverage. However, I am having trouble putting this into my build.gradle. From what I can tell, I need to add a local repository in my build script...
...
apply plugin: "jacoco"
...
buildscript {
repositories {
// Local Repo
// MVN Repo(s)
}
dependencies {
// Classpaths
}
}
jacoco {
toolVersion = "0.6.4.201311160552" // I need this specific version, which isn't on a MVN repo
}
...I tried to add my local repo several ways including...
flatDir(dirs: "lib")
flatDir dirs: "${projectDir}/lib"
maven { url uri("lib") }
one or two other ways I forget
...my lib folder contains the exact contents, unchanged, from the preview build zip's lib folder in the link above. It doesn't seem like gradle is having a problem locating the local repo, but it is having trouble finding the JAR. I assume there is something wrong with the way I am naming it or the way that it is "packaged". I have tried modifying the JAR names but I keep getting the error...
What went wrong:
A problem occurred configuring root project 'myProject'.
Could not resolve all dependencies for configuration ':classpath'.
Could not find :org.jacoco.agent:.
Required by:
:myProject:unspecified
...any ideas why my JAR is not being found? Thanks!
"Answering" my own question, despite the fact that I still haven't quite figured it out. Anyways, here are two links I found that seem to solve my problem...
http://forums.gradle.org/gradle/topics/jacocotestreport_is_skipping
...following some of these instructions allow my tests to run, but I am still not able to run "gradle jacocoTestReport" without it failing.
UPDATE
OKAY! I figured it out, the link above did help me figure it out. My problem was with the asm-all JAR, since there were several, I did not know which one to use. In order to get jacoco working with Java 1.8, you do not need to specify the toolVersion property. All you need to do is add the following to your dependencies block (not the buildscript block, the code block)...
jacocoAgent files(
"$projectDir/lib/org.jacoco.agent-0.6.4.201311160552.jar")
jacocoAnt files(
"$projectDir/lib/org.jacoco.ant-0.6.4.201311160552.jar",
"$projectDir/lib/org.jacoco.core-0.6.4.201311160552.jar",
"$projectDir/lib/org.jacoco.report-0.6.4.201311160552.jar",
"$projectDir/lib/asm-all-5.0_BETA.jar")
...where the asm-all-5.0_BETA.jar is taken from the org.ow2.asm group found at...
http://mvnrepository.com/artifact/org.ow2.asm/asm-all/5.0_BETA
...hope this helps!
for reference, latest jacoco libs are changed so i'm sharing the following snippet:
dependencies{
jacocoAgent files("$rootProject.projectDir/lib/org.jacoco.agent-0.8.3.201904130250.jar")
jacocoAnt files("$rootProject.projectDir/lib/org.jacoco.ant-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/org.jacoco.core-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/org.jacoco.report-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/asm-7.0.jar",
"$rootProject.projectDir/lib/asm-tree-7.0.jar",
"$rootProject.projectDir/lib/asm-commons-7.0.jar"
)
}

Categories

Resources