Spotbugs build issue - java

Built failed while creating aws-sdk-v2 jars due to spotbugs plugin.
Steps to reproduce the error:
clone latest version of aws-sdk-java-v2
In terminal, go to directory and run mvn clean install
Error:
Failed to execute goal com.github.spotbugs:spotbugs-maven-plugin:3.1.11:spotbugs (spotbugs) on project aws-sdk-java-pom: Execution spotbugs of goal com.github.spotbugs:spotbugs-maven-plugin:3.1.11:spotbugs failed: Unable to load the mojo 'spotbugs' in the plugin 'com.github.spotbugs:spotbugs-maven-plugin:3.1.11'. A required class is missing: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
I tried to rebuild the project by deleting spotbugs-maven-plugin but I that didn't solve the problem.

I had no .mavenrc file yet, but recently had added Java 17 to test something via Home Brew. As a result, I started seeing this issue. I created a ~/.mavenrc and added the following to it:
JAVA_HOME=`/usr/libexec/java_home -v 1.8.0`
This allowed me to get back to using Java 8 with Maven just like my default Java version would be.

I had a similar problem and it turned out my installation of Java 15 was the culprit. Once I got maven to use my standard java version (1.8 Corretto) I could build the project again. Use mvn -version to check which java it's currently using.
Personally I had to set JAVA_HOME in my .mavenrc file, setting it in my bash profile didn't help.

Related

Unknown lifecycle phase in maven when specifying a revision

I'm new to maven and I'm having some issues building some code. A colleague uses the following command to build one of our projects:
mvn clean install –Drevision=5.0.0-local-SNAPSHOT –P bld
This works on his machine but not on mine. I get
[ERROR] Unknown lifecycle phase "▒Drevision=5.0.0-local-SNAPSHOT".
Any idea what is could be causing this? I use Maven version 3.6.3 with java 1.8.0_92. Also how do I make a run configuration on Eclipse for the command line above? Do I just just remove "mvn" and add the rest to the "Goals" field?
I guess that the - at the beginning of -Drevision=... is not a real - but some other dash.
Try not to copy/paste, but enter it directly.
howlger already answered the part about Eclipse.

How to Run Eclipse+Maven+JUnit tests in Command Line

When I run mvn clean test, it gives me the following error:
'mvn' is not recognized as an internal or external command, operable program or batch file."
This is the link of my project.
I can run the tests by right-clicking on the Runner.java => Run as => JUnit Test. I can also run the tests from the JUnit 4 Test Explorer Tab.
I have read some articles where it's suggesting to set the PATH for Maven but all of them are about the case where you are installing Maven separately. I am not sure what PATH do I need to set when Maven is coming with Eclipse.
I did not install Maven separately, it came with my Eclipse version.
My Eclipse Version :
Eclipse IDE for Java Developers
Version: 2019-03 (4.11.0)
Build id: 20190314-1200
Some IDEs (IntelliJ for example) have their own version of maven for internal purpose. But it doesn't mean that's able to be used by the command line. If you want to compile your project using mvn clean install/package/deploy/test/etc you must install maven in your machine and set de VARs in the OS.
I guess Eclipse has the same behavior that Intellij, so please also install maven in your machine
This error means that Windows cannot find an executable program called "mvn". This means it is not on your path/current directory.
When you right click and run your junit tests, it invokes it using the JVM, using the java command. I suspect if you type "java -v" into CMD, it will not give you the same error.
Since Windows does not know where to look for maven, you must tell it implicitly, by setting your path to the directory containing the mvn executable. You can lookup "eclipse bundled maven default location" to find this, although it might be worth downloading it separately from the Apache website, and manually specifying the path.

IntelliJ Compilation Error zip END header not found

The Issue
I am unable to compile Java code for an imported Eclipse project on IntelliJ build 182.4505.22 on Java 9 and 10. The following error is displayed when compiling the module, or any individual file:
Error:(1, 1) java: cannot access edu.wit.cs.comp2000
zip END header not found
Details
The structure of the project is as follows:
The full compile-time output is as follows:
Already Attempted
I have reviewed posts here and here, which do not provide any relevant details.
I have attempted compiling on both Java 9 and 10, which makes no difference.
I have written a main method into LinkedBag and attempted to run that independent of JUnit, which results in the same error.
IntelliJ is not correctly displaying the testing icons in my test class, so I suspect that JUnit (or lack of JUnit) is the cause of the issue, however I am unsure how to proceed. Compiling works for other projects (without JUnit tests) just fine.
Updates
The code seems to compile and test as expected on Java 1.8 without issue. Switching to Java 9 or 10 causes the above issue every time. I am beginning to suspect that one of my instructor's dependencies requires Java 1.8 specifically, however I would still like to use newer versions of Java if anyone might have a solution.
As mentioned above, just delete the corrupted cache and restart Intellij.
Running gradle in the commandline can help knowing what you should delete. For instance:
$ ./gradlew --version
Could not unzip /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb/gradle-5.6.2-all.zip to /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb.
Reason: error in opening zip file
and after deleting the folder /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb the problem was solved:
$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip
......
We had this issue when internet connection dropped while Idea was downloading project dependencies. We solved it by deleting the corrupted file from cache. Cache location depends on your build tool, e. g. for Maven it's in ~/.mvn, for Gradle it's in ~/.gradle.
In my case, it was: /.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar
I just removed it and I was able to compile my code.
Just pay attention to the .jar file in your case it's giving an error. Just remove it and you are good to go.
I Had Similar issue in my mac.I just deleted .m2 repository and did maven clean install again worked.
Instead of deleting your whole maven repository you can scan through it locally to find the bad jar file using GNU utils
find <maven-repository-dir> -type f -name "*.jar" -exec zip -T {} \; grep -v OK
I got this error
[ERROR] error reading /Users/username/.m2/repository/io/confluent/common-config/5.5.1/common-config-5.5.1.jar; zip END header not found
I don't know why the jar was corrupted but the error went away when I replaced the jar with my colleagues jar file. Fixing the error temporarily.
In my case, the gradle version of the project was 6.2.2 and the 6.4.1(system default gradle) path was provided in the Intellij gradle settings.
This issue appeared suddenly though. I was working on this project for a long time without any issues. I am not quite sure as to what triggered this issue. The gradle default version package was fine as the gradle build was fine from command line. :)
Referred to suggestions from here
Any one of the below solved the issue on my system:
Provide the path to project gradle version, in gradle settings.
or
Change the 'distributionUrl' value in your gradle-wrapper.properties to have 'all' instead of 'bin'. And also make sure you have gradle-wrapper.properties configured in your intellij gradle settings.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
This can also occurs when you use a dependency that requires to be of type pom (to transitively add all dependencies, useful for BOMs) but without specifying it.
For example if you have a Spring Boot project and use that starter :
<dependency>
<groupId>org.zkoss.zkspringboot</groupId>
<artifactId>zkspringboot-starter</artifactId>
<version>${zkspringboot.version}</version>
</dependency>
Then mvn clean package will give you the following error :
Error: java: cannot access com.example.myproject
And running the app will result in the following error :
java: error reading ...\.m2\repository\org\zkoss\zkspringboot\zkspringboot-starter\2.3.0\zkspringboot-starter-2.3.0.jar;
zip END header not found
because it should not perform any packaging.
Adding the pom packaging type fixes the problem, so that it keeps the artifact simply as a descriptor of dependency versions :
<dependency>
<groupId>org.zkoss.zkspringboot</groupId>
<artifactId>zkspringboot-starter</artifactId>
<version>${zkspringboot.version}</version>
<type>pom</type>
</dependency>
Tweak file watching settings did the trick for me.
For Ubuntu/Mac Run these 2 commands.
sudo echo "fs.inotify.max_user_watches = 524288" | sudo tee /etc/sysctl.d/40-idea.conf
sudo sysctl -p --system
I had a similar issue when I used the dependency thymeleaf-extras-springsecurity4 from org.thymeleaf.extras in a spring boot application.
Updating the dependency to the latest version helped.

Unable to configure Maven in Jenkins

Maven version 3.3.3 (Maven is configured in my system. I'm able to get version number by mvn -version.)
Following is my Maven project in Jenkins:
Which basically asks me to configure Maven.
Below are the only fields available when I select Configure System. Though I gave the path of Maven, the error is not removed and unable to build.
Can someone help on this.
Please check "Jenkins => Configuration => Global Tool Configuration". There you can define your maven-installation not only the the environment-variable MAVEN_HOME.
Afterwards you should be able to select your maven-installation in your project-build.
ln -s /opt/apache-maven-3.5.4/bin/mvn /usr/bin/mvn
run echo $PATH in pipeline script and see paths available to Jenkins user. Once linking with maven bin path, maven started working. To check, run mvn -v in the pipeline.
First you should configure a JDK and NOT an JRE. Furthermore the rootPOM location is relative to the Jenkins Job Workspace which means usually only pom.xml nothing more...

Integrating IntelliJ with Maven

I have set M2_HOME variable to the required directory in .bash_profile, still I am getting the following error:
Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.[ERROR] Maven execution terminated abnormally (exit code 1)
One solution (but it's only a workaround) may be to set console argument
"-Dmaven.multiModuleProjectDirectory="
Then the project should work.
I have the same problem while building maven projects from eclipse with system maven installation.
Have you configured maven in IntelliJ?
You can change your maven's version to 3.1.1.
I met the problem too: My version of maven was 3.3.3, and then I changed it to 3.1.1 and it worked.

Categories

Resources