While trying to run "gradle test jacoco" in gitbash I am getting TestExecutionException, NoClassDefFoundError, ClassNotFoundException - spring-mvc

While trying to run jacoco in my gradle project, I am getting exceptions.
I have added following dependencies:
compile "org.jacoco:org.jacoco.report:0.7.8"
compile "org.jacoco:org.jacoco.core:0.7.8"
compile "org.ow2.asm:asm-all:5.1"
I also tried with different options like providedCompile, testCompile also.
I am getting this exception, while trying to run "gradle test jacoco" in gitbash.
Exceptions:
org.gralde.api.tasks: TaskExecutionException: Exception failed for
task:'practice-app:jacocoTestReport'
Caused by: java.lang.NoClassDefFoundError:
org/jacoco/report/IReportVistor
Caused by: java.lang.ClassNotFoundException:
org.jacoco.report.IReportVisitor
I also verified other checks like jacoco jars available in my local gradle repo etc.

I had also experienced the similar problem during Jacoco integration in one of our gradle project. The plugin somehow did not bring the required jars. Then, I tried to add all the dependencies manually
say :-
compile "org.jacoco:org.jacoco.report:0.7.8"
compile "org.jacoco:org.jacoco.core:0.7.8"
compile "org.ow2.asm:asm-all:0.7.8"
etc., but that trick also did not work. Still got classnotfound exception against jacoco jars. Then after a lot hit & trial, I came to know about jacocoClasspath. I did the followings:
1) First changed Jacoco version to
jacoco {
toolVersion = "0.7.8+"
}
As got some incompatibility version issue (Don't remember the exact error/exception).
2) Then, added the below code in build.gradle to ensure that required dependencies are present in the jacoco class path.
jacocoTestReport.doFirst {
configurations.testRuntime.each { jacocoClasspath += files(it); }
}
Notes:
1) doFirst will be executed before jacoco task gets executed.
2) I just added whatever present in my runtime to the jacocoClasspath. You may refine the code, to add only the required jars to the jacoco class path.

Related

How can i fix Bad JNI version returned from JNI_OnLoad error on flutter

When I extract the app as apk and test it on a real Android device, it crashes, but when I run it as debug it works fine. The cause of the error is pub.dev --> video_editor library. I got this error output from Firebase:
Caused by java.lang.UnsatisfiedLinkError:
Bad JNI version returned from JNI_OnLoad in "/data/app/com.projectName--b7nYjATxtDAUxnuC_rpnQ==/base.apk!/lib/armeabi-v7a/libmobileffmpeg.so": 0
java.lang.Runtime.loadLibrary0 (Runtime.java:1016)
java.lang.System.loadLibrary (System.java:1657)
com.arthenica.mobileffmpeg.Config.<clinit> (Config.java:146)
com.arthenica.mobileffmpeg.Config.nativeFFprobeExecute (Config.java)
com.arthenica.mobileffmpeg.FFprobe.execute (FFprobe.java)
com.arthenica.mobileffmpeg.FFprobe.getMediaInformationFromCommandArguments (FFprobe.java)
com.arthenica.mobileffmpeg.FFprobe.getMediaInformation (FFprobe.java:48)
com.arthenica.flutter.ffmpeg.FlutterFFmpegGetMediaInformationAsyncTask.doInBackground (FlutterFFmpegGetMediaInformationAsyncTask.java:21)
com.arthenica.flutter.ffmpeg.FlutterFFmpegGetMediaInformationAsyncTask.doInBackground (FlutterFFmpegGetMediaInformationAsyncTask.java:2)
android.os.AsyncTask$2.call (AsyncTask.java:333)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
java.lang.Thread.run (Thread.java:764)
Enabling ProGuard on releases older than v0.2.4 causes linking errors. Please add the following rule inside your proguard-rules.pro file to preserve necessary method names and prevent linking errors.
-keep class com.arthenica.mobileffmpeg.Config {
native <methods>;
void log(int, byte[]);
void statistics(int, float, float, long , int, double, double);
}
and also make sure that mavenCentral() is defined as a repository in your build.gradle and it is listed before jcenter().
Refer from flutter ffmpeg documentation https://pub.dev/packages/flutter_ffmpeg

error building spring webserver from corda samples

I am trying to run this spring webserver project locally as per https://github.com/corda/samples/tree/release-V4/spring-webserver using command "gradlew.bat runPartyAServer" and getting the following error "2019-08-14 18:08:20,522 main ERROR Rewrite contains an invalid element or attribute "ErrorCodeRewritePolicy"
", can you please help me fix it? PS: The corda-example nodes are already started and running. (edited)
I have already built the corda examples and they are running but spring webserver is not running but producing error
The reason for the error could be the different versions of dependencies.
You can clear the cache and do clean deploy of nodes and run them.
Once the nodes have started, start runPartyAServer again.
The exception
"ERROR Rewrite contains an invalid element or attribute "ErrorCodeRewritePolicy"" is related to version of log4j2.xml.
Most likely, the ErrorCodeRewritePolicy attribute is not present in the version of log4j2.xml file downloaded by the application.
Following is the structure of code containing ErrorCodeRewritePolicy in a log4j2.xml (see https://github.com/corda/corda/blob/master/config/dev/log4j2.xml)-
<Appenders>.....
<Rewrite name="Console-ErrorCode-Selector">
<AppenderRef ref="Console-Selector"/>
<ErrorCodeRewritePolicy/>
</Rewrite>
<Rewrite name="Console-ErrorCode-Appender-Println">
<AppenderRef ref="Console-Appender-Println"/>
<ErrorCodeRewritePolicy/>
</Rewrite>.....
Try replacing $log4j_version by "2.7" in the build.gradle.
Delete the cache and build folders and allow the gradle to download dependencies again.
Replace -
compile "org.apache.logging.log4j:log4j-web:$log4j_version"
By -
compile "org.apache.logging.log4j:log4j-web:2.7"
After alot of debugging, tracing in to the internals of Spring, I think there is a bug in the gradle.build file. I commented out these from the dependencies section:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile "junit:junit:$junit_version"
// Corda dependencies.
compile "$corda_release_group:corda-core:$corda_release_version"
compile "$corda_release_group:corda-rpc:$corda_release_version"
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") // {
// exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
// }
// compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
// compile "org.apache.logging.log4j:log4j-web:$log4j_version"
runtime "$corda_release_group:corda:$corda_release_version"
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-reflect
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.61'
}
Now my code runs without the annoying ErrorCodeRewritePolicy error messages, AND I can configure the log levels from applications.properties.

Gradle implementation vs compile in jar task

I can successfully use Gradle to compile a fat JAR, but having trouble running the JAR after recently switching from the "compile" dependency specification to the "implementation/api" specification. I have isolated that the problem occurs in only one of the two following cases. The application runs in either case inside IntelliJ.
first/problem:
dependencies {implementation 'no.tornado:tornadofx:1.7.18'}
second/works:
dependencies {compile'no.tornado:tornadofx:1.7.18'}
The JAR compiles in both cases. The problem appears when I attempt to start the first case JAR on the command line and it throws the following error.
C:\aaa_eric\code\testr\mic\build\libs>java -jar mic-1.0-snapshot.jar
Error: Could not find or load main class app.MyApp
Caused by: java.lang.NoClassDefFoundError: tornadofx/App
Here is the JAR task in build.gradle. Is it possible that the tornadofx dependency is available at compile time, but not at run time? Thanks for any help.
jar {
manifest {
attributes 'Main-Class': 'app.MyApp'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
Changing configurations.compile.collect to configurations.compileClasspath.collect fixed the problem for me.
I was having the same problem and stumbled across this in https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/ConfigurationContainer.html:
An example showing how to refer to a given configuration by name in
order to get hold of all dependencies (e.g. jars, but only)
apply plugin: 'java' //so that I can use 'implementation', 'compileClasspath' configuration
dependencies {
implementation 'org.slf4j:slf4j-api:1.7.26'
}
//copying all dependencies attached to 'compileClasspath' into a specific folder
task copyAllDependencies(type: Copy) {
//referring to the 'compileClasspath' configuration
from configurations.compileClasspath
into 'allLibs'
}
One thing to note is that configurations.compileClasspath.collect worked for me even when I was using the compile specification instead of implement.

Can't understand gradle jar task code that creates executable fat-jar

I am learning Gradle but I don't understand the jar task code that creates a jar with all the dependencies inside ( taken from Gradle Cookbook ):
jar {
baseName = jarBaseName
manifest { attributes "Main-Class": mainClass }
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
My questions are:
1.The task name is jar. Because it's not written like jar<<{...} I'm assuming that this is run in the configuration phase, and not the execution one. Am I correct?
2.What exactly is configurations.compile? I'm assuming that some kind of dependencies classpath is queried, and each jar is zipTree-ed. Then all of this stuff is merged with the base classpath
. Please elaborate about it
3.The zipTree method, I'm assuming it kind of unarchives each jar but I'm not sure. Am I correct?
Regards,
Yes You're correct. When no action added (mostly with << see docs) the code is run at configuration phase. The code You provided is also run at configuration phase.
configurations.compile refers to a configuration named compile using configurations object (a kind of a configurations container). Prior to gradle 2.0 compile configuration is provided by default with java plugin. AFAIR now it's called javaCompile. According to zipTree You're also correct.
Yes You're.

NoClassDefFoundError: org/jbox2d/collision/shapes/Shape in netbeans

I am trying to add jbox2d as a dependency to my project in netbeans (playn-jbox2d-1.1-SNAPSHOT.jar), but at run time, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jbox2d/collision/shapes/Shape
All other classes can be accessed fine, just not Shape.
I simply right clicked dependencies in my core directory and did add dependency and searched for jbox2d.
Anyone know what could be wrong?
What version of jbox2d do you have, as a dependency? You can crosscheck in the dependency jar file, if that class (Shape.class) exists or not?
EDIT: Most of the times, 'NoClassDefFoundError' happens due to incorrect classpath settings or when there's more than one class (or jar file) in the classpath, with the same namespace.

Resources