maven fails to recognize jetty is installed - macos

fresh meat newbie on GCP / Maven on
OSX 10.14.3 with Visual Studio Code (latest)
GCP SpringBoot API with Maven
other questions on jetty seem to be further along than me.
the 'flow' below is to reveal steps to get to my question in the title...I think it's important to see how I got to where I am, and if you are so kind to offer help, you would want to know this? ok, here we go...
I downloaded the GCP getting-started-java github example and want to run the bookshelf example.
When I look at the multiple POM files I see that each references a project ID for GCP.
I can't use the same project ID as they are unique, just like GCP bucket names.
So, when I run
gcloud init
and select or create a configuration and make my own project with a unique project id, does that automatically override every POM file definition of project ID? Or do I need to do some maven clean command to change it???
Well... when I RTFM in each folder, it says to
mvn clean jetty:run-exploded -Dbookshelf.bucket=MY-BUCKET
heck even tried:
mvn jetty:run
and I get a build failure that says:
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups
so... I
brew install jetty
Then to 'get started' jetty says I have to copy the 'plug in' details into my POM file... which one, as there are several??
But when I installed the VS Code plugin, it already updated all POM files; I still get the "No plugin found for prefix 'jetty'" error
I guess I'll stop with that question:
how do I get maven to 'know' that jetty is installed and work with it?

When you use the shorthand plugin goal jetty:run-exploded or jetty:run maven is attempting to find the plugin. This shorthand form will need to resolve the groupId:artifactId:version:goal in order to run.
The long-hand form of that would be ...
$ mvn org.eclipse.jetty:jetty-maven-plugin:9.4.15.v20190215:run
To fix this, just add the plugin to your pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.15.v20190215</version>
</plugin>
</plugins>
</pluginManagement>
...
</build>
</project>
The above will always use that specific version of jetty-maven-plugin when you use the shorthand syntax.
Alternatively, and with less control over which version to use, is to setup a pluginGroup in maven's $HOME/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<pluginGroups>
<pluginGroup>org.eclipse.jetty</pluginGroup>
</pluginGroups>
...
</settings>

Related

Maven calling plugin from command line in parent pom

My project sturcture:
- something-parent
-- something-one
-- something-two
something-parent -> pom.xml:
<packaging>pom</packaging>
<modules>
<module>something-one</module>
<module>something-two</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>io.github.something</groupId>
<artifactId>something-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
</plugins>
</build>
Now I want to execute mvn something:help, but I can't: No plugin found for prefix 'something'.
If I remove modules section - it works. It also works in other modules.
It just doesn't work in parent module with modules section. I couldn't find any documentation or literally anything describing this, is this intended? Is there any workaround?
I know io.github.something:something-maven-plugin:1.0.0:help will work, but I need the shortcut version to work.
//Edit1 - I know about settings.xml solution, but it requires manual edit by user, I would like something on a project level
//Edit2 - found out another quirk, it works when I do mvn something:help -N
I understand that you want to use a short name to refer the plugin when calling it from the command line.
To do that, you have to define a plugin group in your settings.xml, as of https://maven.apache.org/settings.html#plugin-groups
In your case it would be:
<pluginGroups>
<pluginGroup>io.github.something</pluginGroup>
</pluginGroups>
This allows you to call:
mvn something:goal

How to upload jars with different classifiers and same pom.xml on Nexus 2 from REST API with curl?

I've been struggling with this for quite some while.
Background: We have some Jenkins jobs that produce jars and other jobs that upload the jars to nexus. In our case we are looking for myJar-1.0.jar and myJar-1.0-myClassifier.jar. Obviously they are both produced with the same pom.xml file.
What I am trying to achieve is to upload both of them on Nexus (We use Nexus2) through the REST API with a curl command using the pom.xml.
The pom.xml file looks something like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>myJar</artifactId>
<version>1.0</version>
<name>My Name</name>
<packaging>pom</packaging>
<properties>
<otherJar.version>1.5</otherJar.version>
...
</properties>
<dependencies>
<dependency>
<groupId>x.y</groupId>
<artifactId>art</artifactId>
<version>{$otherJar.version}</version>
</dependency>
...
</dependencies>
</project>
The curl command that I'm using to upload (the jar without the classifier) is:
curl -v -F r=releases -F hasPom=true -F e=jar -F file=#pom.xml -F file=#myJar-1.0.jar -u user:pass http://link/to/nexus/service/local/artifact/maven/content
and this works as expected. The jar is uploaded to nexus with the groupid, artifactid and version mentioned in the pom.xml file.
My question is - after I upload this jar, how can I upload the jar with the classifier provided we have the same pom.xml?
Should I alter the pom.xml file? If so, how?
Should I modify the curl command? I tried adding -F c=myClassifier but that didn't work. That resulted in an error produced by Nexus: <html><body><error>Repository with ID='releases' does not allow updating artifacts.</error></body></html> (because there is already an artifact with same groupid, artifactid and version - the one that I just uploaded; it seems that the classifier is ignored)
So I tried multiple solutions and could not come up with one that satisfies my needs (uploads multiple jars with the same pom and different classifiers through the REST API) with one or more calls.
I ended up installing maven on the machine that was running my scripts and using the maven deploy:deploy-file as follows:
maven deploy:deploy-file
-DpomFile=pom.xml
-Dfile=myJar-1.0.jar
-Dpackaging=jar // this doesn't have to be specified, it will be taken from the pom file, however in my case the pom was specifying <packaging>pom</packaging> and the jar ended up with .pom extention
-Dclassifiers=myClassifier // here you can define multiple classifiers, comma-separated
-Dtypes=jar // same as above
-Dfiles=myJar-1.0-myClassifier.jar // same as above
-DrepositoryId=nexus
-Durl=http://host:port/nexus/content/repositories/releases
You can find the full documentation here.
Also, please note that you have to define your nexus repository credentials in the maven's configuration file (maven_home/conf/settings.xml).
Find the node servers in that file and add something similar to this:
<server>
<id>nexus</id>
<username>yourUserName</username>
<password>yourPass</password>
</server>
In the end I want to stress the fact that I think this is a missing feature/bug of Nexus2's REST API. As you can see from the snippet above, this can be achieved by uploading the jars with maven and this can also be achieved manually from the Nexus interface. However, I did not manage to do it through the REST API. It could be possible because I did not find the right way to call it, but I couldn't find (almost) any documentation either.. a bummer.
Also, final note for this question - I will leave this unsolved since this does not answer my original question (How can this be achieved through the REST API?).

IntelliJ IDEA - Run/debug doesn't copy resources

I have a maven project which is packaged as WAR. The POM looks something like the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>my_app</artifactId>
<packaging>war</packaging>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
...
</plugin>
...
</plugins>
</build>
</project>
When I manually run the command mvn package, a WAR is generated with directory target/my_app where my web resources (JSP, CSS, JS, images, etc.) are copied to. The generated WAR, if uploaded to an Application Server, works fine.
However, if I use IntelliJ IDEA's Run/Debug configuration (which is configured to deploy the WAR to an Application Server (JBoss if that matters)) to do the same, I don't see the web resources. Only configuration XMLs and compiled classes is present in the target/my_app directory. The applicaiton server starts up all fine without any errors and WAR is deployed successfully, however I can't accesss it as it returns 404.
How can I acheive what I get when building and manually uploading the WAR using Run/Debug of IntelliJ IDEA?
UPDATE:
Before launch tasks are:
Build
Build 'my_app:war exploded' artifact
I had the same issue after installing 2018.1 IntelliJ IDEA. Reverting back to version 2017.3 solved the problem. It looks this is a bug with the new version since I had the same settings for both. Hope this helped.
I had similar issue in which when I was running from the command line then it was copying all the resources (example JSP etc.) but Intellij was not copying it.
As part of workaround I added the goal of 'war:exploded' along with 'compile' then it resolved my issue.
So in Maven config command line parameters will be (may differ for you):
clean compile war:exploded
Screenshot for reference.

Change version of Maven project without manipulating the POM file

Is it somehow possible to change the version of a Maven project without manipulating the POM file?
Let's say I have a Maven project with version 1.5.0-SNAPSHOT but I want to build it as 1.5.46.
The Versions Maven Plugin unfortunately modifies the POM files.
Since Maven 3.5.0 this is possible using a special predefined property: ${revision}. Define the property with a default value (e.g. 1.5.0-SNAPSHOT) and when needed, set it during execution to a specific version (e.g. 1.5.46).
For example, define the following in your pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>foo</artifactId>
<name>Foo Module</name>
<version>${revision}</version>
...
<properties>
<revision>1.5.0-SNAPSHOT</revision>
</properties>
</project>
Build it using the default value:
mvn clean install
This will produce an artifact identified as org.example:foo:1.5.0-SNAPSHOT.
In order to build a specific version, set the revision property, for example:
mvn clean install -Drevision=1.5.46
This will produce an artifact identified as org.example:foo:1.5.46.
For further details, see the Maven CI Friendly Versions page.
Try to override project version with
mvn versions:set -DnewVersion=<version>
in your particular case:
mvn versions:set -DnewVersion=1.5.46
You can
Make a copy of your pom as temppom.xml
Replace the version in temppom.xml
Build with mvn -f temppom.xml.
Delete temppom.xml.
Maven supports delivery friendly versions, see https://issues.apache.org/jira/browse/MNG-5576 .
For more details I would suggest to talk with #khmarbaise
The plugin provides a goal to revert the changes made by it:
mvn versions:revert

Plugin is not being found after I install it in local repo

I have written a plugin and to install it in the local repository I run the command :
mvn install
The plugin is successfully added to my local maven repository but when I run :
com.tools:generate:0.0.1-SNAPSHOT:generatepom
I receive the error :
plugin com.tools:generate:0.0.1-SNAPSHOT or one of its dependencies
could not be resolved: Failed to read artifact descriptor for
com.tools:generate:jar:0.0.1-SNAPSHOT: Failure to find
com.tools:generate:pom:0.0.1-SNAPSHOT in
https://nexus.mydomain.com:8181/prod/content/groups/level0/ was cached
in the local repository, resolution will not be reattempted until the
update interval of nexuspro-level0 has elapsed or updates are forced
-> [Help 1]
It seems to be searching for the plugin on Nexus even though the plugin is installed locally. How can I configure maven to run the plugin in the local repository ?
Here is the build & beginning of pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tools</groupId>
<artifactId>generate</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.tools</groupId>
<artifactId>generate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<repositoryUri>http://repository.sonatype.org/service/local/lucene/search?sha1=</repositoryUri>
</configuration>
</plugin>
</plugins>
</build>
most likely your plugin's pom contains different identification (groupId,artifactId,version).
Also, make sure that you specified maven-plugin there.
If it is not the case, please provide plugin's pom excerpt, or its build log excerpt (the "istalling ..." part).
You can read about developing plugins here.
I would suggest to turn your approach around and deploy the plugin to the remote repository.
If that is not desired it should however work fine. You might be running into a problem with your Maven repository meta data. I would try to run
mvn -U com.tools:generate:0.0.1-SNAPSHOT:generatepom
forcing an update as a next step.

Resources