Unknown lifecycle phase in maven when specifying a revision - java

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.

Related

Spotbugs build issue

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.

The difference between invoke maven directly in shell and invoke it from intellij IDEA

Edit 3:
I also tried to set maven proxy through java option parameters mentioned at this thread.
Edit 2:
I'm sure intellij idea are using same settings.xml, same maven binary and the same local repository as system maven.
Edit 1:
I tried to check build log of each workload, the main difference is about how to invoke maven at the very beginning of build log.
For intellij idea, it's like below:
C:\Program Files\Java\jdk1.8.0_101\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\eugene\IdeaProjects\alluxio -Dmaven.home=C:\apache-maven-3.5.4-bin\apache-maven-3.5.4 -Dclassworlds.conf=C:\apache-maven-3.5.4-bin\apache-maven-3.5.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA\plugins\maven\lib\maven-event-listener.jar" -Dfile.encoding=UTF-8 -classpath C:\apache-maven-3.5.4-bin\apache-maven-3.5.4\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version2019.2.4 -DskipTests=true -T 2C clean install -DskipTests -Dmaven.javadoc.skip -Dfindbugs.skip -Dcheckstyle.skip -Dlicense.skip
For system shell, maven just launched without this invoking info.
I'm using maven to build a project Alluxio from source code.
I tried both Windows 10 and Ubuntu and found same issue when using intellij idea, let me clarify it into details.
OS: windows 10/ Ubuntu 18.04
Maven: 3.5.4
Build command: mvn -T 2C clean install -DskipTests -Dmaven.javadoc.skip -Dfindbugs.skip -Dcheckstyle.skip -Dlicense.skip
The Alluxio can be built successfully using maven 3.5.4 directly but failed with several errors using intellij idea. What makes me confused is that I configured intellij idea to use system maven 3.5.4 and used exactly same build command. Why errors happened here but not in system shell.
The error I met is like:
Failure to find com.google.guava:listenablefuture:jar:sources:9999.0-empty-to-avoid-conflict-with-guava in https://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
And also like:
sourceFile C:\Users\eugene\IdeaProjects\alluxio\table\server\underdb\target\alluxio-table-server-underdb-2.2.0-SNAPSHOT-jar-with-dependencies.jar does not exist
The method used to trigger maven build from intellij idea:
Click maven icon at right top corner
Click Execute Maven Goal
Input mvn -T 2C clean install -DskipTests -Dmaven.javadoc.skip -Dfindbugs.skip -Dcheckstyle.skip -Dlicense.skip and enter to launch build
The maven settings in intellij idea is as default except change the maven binary from build-in binary to system maven 3.5.4.
Thanks for your help in advance.
I have seen two issues that will produce an error message like you see and it has nothing to do with IntelliJ.
The first occurs when Maven fails to successfully download an artifact from a repository (e.g., network interruption). It will mark the artifact as failed and will refuse to retry until some period lapses. Cleaning your local Maven cache or removing that artifact's folder will fix this issue.
The second occurs when two separate Maven builds attempt to download the same artifact from different repositories. Many years ago, Maven had a problem with people building modified versions of open-source projects (e.g., Apache Commons) and publishing them in a publicly available repository. I don't remember the details but this caused lots of issues. Maven now records the repository used to fetch an artifact. When two Maven projects use different repositories, the second one built will fail because the repository does not match. I had this occur when switching to a private repository, Artifactory, and not having all my projects migrated yet.
Since you are attempting to build the same project with two tools, your issue appears to be a variant of the second issue. I suspect that IntelliJ is using a different settings.xml than what you have available from the command line and that IntelliJ is using different repositories. Repositories can be specified in the settings.xml as well as the project's POM.
Try deleting your local cache and building from IntelliJ first. If it succeeds and then the shell build fails, this is your problem.
Update: See this answer for more details on why Maven started tracking the repository but note the the tracking file is now called _remote.repositories.
https://stackoverflow.com/a/16870552/252344

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.

Java project runs in IDE (IntelliJ Idea) but fails to run after Maven build

I have a Java project that is ready to ship, but i have stumbled at the last hurdle. The program runs fine in the IDE, but after i run mvn clean install and the target jar is created successfully, the application fails both on the command line AND in the IDE. I can get it to run again in the IDE by doing a rebuild from within the IDE.
Has anyone else experienced something similar?
The error after the mvn clean install is
2014-08-08_10:38:20.328 INFO coza.modh.fxplatform.Controller - Application start
2014-08-08_10:38:20.344 INFO c.m.f.c.p.DataSourceFactory - Connecting to Database.
2014-08-08_10:38:20.499 INFO coza.modh.fxplatform.Controller - Model created
Exception in thread "main" java.lang.NullPointerException
at coza.modh.fxplatform.view.MainView.<init>(MainView.java:46)
at coza.modh.fxplatform.Controller.startup(Controller.java:40)
at coza.modh.fxplatform.Application.main(Application.java:7)
The line it fails on looks like this:
setContentPane(contentPane);
If i rebuild from within the IDE then the variable is not null when it gets here, but after the mvn command the variable is null when it gets to this point.
EDIT: Someone pointed out that it might be related to the fact that i used the intelliJ GUI designer tools and that Maven might not gel with it. Possibility?
I had a similar problem today. To solve the issue -
Firstly, add the following to the pom.xml
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>5.0</version>
</dependency>
Secondly, as you stated, use the correct maven plugin to create the build.
See this for step by step instruction.
Unlikely that contentPane is null, but check. Do a clean build anyway. Maybe the line number is not entirely correct.
Normally the problem are resources, like an application icon.
They are not File but zipped inside the jar.
So paths like /src/main/resources/... will not do.
Neiter using a backslash \, and
furthermore the file paths are case sensitive.
This can be caused by different library versions, do you have changed the build path in Eclipse? (Project->Properties->Build Path -> Libraries). There should only be "JRE System Library". If there is more, then it is possible that it is be loaded instead of one of your Maven dependencies. You using "mvn clean install" means it is compiled against the Maven dependencies and thus it runs differently.
Install Maven on the system(not having IDE) before running the code
ensure you've got system property M2_HOME set to your Maven installation location and also Maven bin folder added to PATH
go to the directory,containing pom.xml of your project and type "mvn install" plus Enter to build your project
if it's for example simple project,packaged as JAR,you can run it then by typing something like this in the console:
$ java -cp target/simple-1.0-SNAPSHOT.jar org.yourcompany.projectNam.App
and Enter

Using maven-release-plugin in Eclipse

I recently tried to use maven-release-plugin since it is apparently the recommended way of building and packages releases in the Maven universe.
However I wanted to use this within Eclipse, as the rest of my development workflow is Eclipse based. I normally run Maven commands via the m2eclipse plugin provided as part of Eclipse Juno (4.2)
I noticed a few oddities when I tried to run "release:prepare" within Eclipse:
Some extra files were created in the root project directory - "pom.xml.releaseBackup" and "release.properties". Do they really belong there? Have I got the release directories set up correctly? I wouldn't really consider these temporary artifacts as part of my source code tree......
The pom.xml gets manually overwritten with the updated release number. Eclipse warns you and is happy to reload the updated version - but is this generally safe?
The prepare ultimately fails giving the error [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project clisk: Failed to invoke Maven build. Error configuring command-line. Reason: Maven executable not found at: C:\Users\Mike\git\clisk\EMBEDDED\bin\mvn.bat -> [Help 1] - presumably because I am using the built-in Maven excetable provided by m2eclipse rather than the command line. I guess I could install command line maven as well.... but is that sensible or will it just cause more problems?
Given these kind of issues, Is there a way to get maven-release-plugin to work smoothly within Eclipse, or should I just give up and continue to do releases manually?
I have been using release plugin, but only from command line.
Re. 1. The backup files that release plugin creates are needed if something goes wrong in time of preparing the release. You can always rollback the prepared release using release:rollback command. When you do release:perform they will be deleted.
Re. 2. The plugin changes the version number from snapshot version for example: 0.0.1-SNAPSHOT: to release version: 0.0.1. Then after release:perform release version is moved to the maven repository and release plugin changes version again to 0.0.2-SNAPSHOT. Now you can use you full released (tested) version in your testing or production enviornment and snapshot version for developping purposes.
Re. 3. I don't know what is causing the problem, but I don't see the problem by using release plugin from command line.
Also mvn 3.3.3 installs a mvn.cmd file, instead of a mvn.bat file in Windows.
You should copy mvn.cmd to mvn.bat
Well i know this link is OLD , but to help some on who reffers this link for the issue 3.
Install maven separately on to local Box and give the path of the installation under Windows->Preferences--> maven--> Installation. Also you have to define the same in the run configuration within the Eclipse.
Attached is a link that explains the same.
http://maven.40175.n5.nabble.com/Build-Failure-prepare-release-td510949.html
You might be able to overcome the error you mention by installing command line Maven and configure Eclipse to use that rather than the embedded one by choosing Window -> Preferences -> Maven -> Installations, but I agree with the advice of making your releases outside Eclipse.

Categories

Resources