Using maven-release-plugin in Eclipse - java

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.

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.

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

How to prevent IntelliJ from asking to provide the Scala SDK after every Gradle build?

I'm using IntelliJ IDEA (15.0.3) to write a project in Scala over Spark.
Every time I build using the following command
./gradlew clean build idea
IntelliJ pops up the message 'No Scala SDK in module' and asks to setup the Scala SDK version.
Is there a way to permanently specify the SDK version so that building with Gradle won't override it?
In general you don't need to run the idea task with every build. That task generates IDEA project files so you're able to open the project from within the IDE - you usually only need to run it once when setting up the project. Running the task over existing project files can (partially) overwrite them, depending on how the task is configured and apparently does override the SDK configuration changes made in your case.
So just running ./gradlew clean build when building should solve your issue (unless I'm missing/misunderstanding part of your question).

Maven Issue SurefireReportParameters

I've been trying to build an app but when I run maven, I catch this exception:
java.lang.ClassNotFoundException: org.apache.maven.plugin.surefire.SurefireReportParameters
I installed the maven-plugin manually, but the issue still continues. Any suggestion will be appreciated.
There are a few things that you should check about this problem.
I will enumarate then here so you could check.
Check if you defined the JDK instead of the JRE on your path enviroment variables. Maven does not work properly only with the JRE. To check that go to your console and se if the javac -version command works.
Check if you have the M2_HOME variable defined on your enviroment variables with the path where you installed maven.
Since you are having a ClassNotFoundException on the SurefireReportParameters class check if the correspondent jar is on your local repository. It normally is on maven_path\repository\org\apache\maven\plugins\maven-surefire-plugin there it should have folder with versions and inside it a JAR file with the name: maven-surefire-plugin-x.xx.jar.
Sometimes it happens that JAR files get corrupted from outside events of the O.S. or the IDE leading to the ClassNotFoundException as it would be very difficult to find all corrupted JARs I usually recomend to redownload the entiry repository again. Note that depending on the size of your project and number of dependencies you have on it this operation will take some time to complete. In order to do that you go to your repository folder (e.g. c:\maven\repository) and rename it (just the repository folder e.g. c:\maven\repository_) or delete it (just repository folder) then go to your project and run mvn install
One of this options should solve your problem. And as we discussed on the comments we already know which one it was. ;)
There are solutions posted for a similar question, but in the context of the Spring Framework.
Spring Boot fails to run maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter
One answer is to use version 3.0.0-M1 of the maven-surefire-plugin.

Eclipse won't believe I have Maven 2.2.1

I have a project (built from an AppFuse template) that requires Maven 2.2.1. So I upgraded to this (from 2.1.0) and set my path and my M2_HOME and MAVEN_HOME env variables.
Then I ran mvn eclipse:eclipseand imported the project into Eclipse (Galileo).
However, in the problems list for the project (and at the top of the pom.xml GUI editor) it says:
Unable to build project
'/export/people/clegg/data/Workspace/funcserve/pom.xml;
it requires Maven version 2.2.1
This persists whether I set Eclipse to use its Embedded Maven implementation, or the external 2.2.1 installation, in the Preferences -> Maven -> Installations dialog.
I've tried closing and reopening the project, reindexing the repository, cleaning the project, restarting the IDE, logging out and back in again, everything I can think of! But Eclipse still won't believe I have Maven 2.2.1.
I just did a plugin update so I have the latest version of Maven Integration for Eclipse -- 0.9.8.200905041414.
Does anyone know how to convince Eclipse I really do have the right version of Maven? It's like it's recorded the previous version somewhere else and won't pay any attention to my changes :-(
Eclipse allows you to specify an external Maven installation. But there's a catch. :(
Have a look at Windows > Preferences > Maven > Installations.
You will see a message like this:
Note: Embedded runtime is always used for dependency resolution, but does
not use global settings when it is used to launch Maven.
To learn more, visit the maven web page.
Translating to English, it means that Eclipse will continue to employ its internal Maven instance in order to perform some tasks.
When you "Run As > maven install" it will run your pom.xml script employing the external Maven instance you specified but when Eclipse performs some of its internal stuff, it will continue to use the embedded Maven instance, whatever version it is.
(edited)
As far as I know, when you install M2Eclipse you are implicitly defining which "internal Maven instance" you will have, which is exactly that one packaged by the plugin.
In the plugin configuration, you can add external Maven instances by telling where they are installed.
If you are using a recent m2eclipse version, you can try this too:
<prerequisites>
<maven>>=2.2.1</maven>
</prerequisites>
Notice the greater than in >=2.2.1. It works fine for me.
A common source of trouble (of this kind) is if you change global preferences and don't remember or know that you have enabled some project specific settings. At least it's a chance that the global setting is now set to use the external maven but the project setting is still set to 'embedded'.
M2Eclipse uses an embedded maven instance, not the maven instance you have installed on your system.
Have you tried switching workspaces?
You can still reference the same project in the new workspace. This would provide about as much of a reset as you can do in terms of eclipses internal settings.
Try creating your eclipse project with mvn project:m2eclipse or use the maven import option under import project.
Using m2eclipse, my fallback in these situations is to do Maven > Update Dependencies and then Maven > Update Project Configuration. The first is just me being supersticious, but the second will rewrite .project and .classpath.
As Pascal says about, m2eclipse can also be pointed at an external instance. I've done this in the past, though not at 2.2.1.
Dan
I got the same issue. Resolved it by restarting the system because every time you change the 'Path' in environment variables you should restart the system or else if would not pick the changes.

Categories

Resources