Is there a way to get the deploy destination in Maven - java

I am trying to configure a Maven plugin in a parent POM file. I need to configure this plugin so that it runs outside of the standard Maven lifecycle through a plugin invocation.
mvn some-plugin:plugin-goal
The configuration item I'm seeking is the deploy destination for the Maven artifact. In other words, the path to the artifact in a Maven repository.
I would like to add a configuration to my parent POM like the one below.
<plugin>
<groupId>com.something.plugins</groupId>
<artifactId>some-plugin</artifactId>
<configuration>
<location>com/my/groupId/${project.artifactId}/${project.version}/${project.build.finalName}.${project.packaging}</location>
</configuration>
</plugin>
This string (shown below in isolation) will give me the deploy destination for the target. However, it is not dynamic and can't be used in a parent POM because the groupId path (com/my/groupId) is hard-coded. My parent POM does not know the groupId of its children.
com/my/groupId/${project.artifactId}/${project.version}/${project.build.finalName}.${project.packaging}
Is there a property in Maven to get the deploy destination within a Maven repository? Or alternatively a property to retrieve the groupId as a path?
Also, I understand that I get create this string with a Groovy script. However, I'm not running the plugin during the standard Maven lifecycle, but instead run it as part of a plugin execution. So the Groovy script would not run.

Related

How declare maven dependecny from URL?

Maven has repositories and dependecies. Some plugins allow to use s3 or github as repository. But is there something to use direct URL? Like:
<dependency>
<groupId>my-group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>some-version</version>
<url>https:someurl</url>
</dependency>
May be define URL and dependency info (group and artifact) in properties and for it installed during some maven phase.
Is it possible?
No.
Maven resolves dependencies from Maven repositories. So you cannot just add a JAR that is present at some URL. The JAR has to come from a Maven repository and (if it is not MavenCentral or already specified in your settings.xml or POM), you need to add it.
Yes this is officially supported but not in as convenient a mechanism as you perhaps desire.
Maven resolves dependencies against your local repository. If it can't find them there, it then tries to resolve them against any remote repositories you have configured.
Therefore, if you manually install the jar into your local repository, Maven will find it and use it.
To do this you must:
Download the jar
You have to do this yourself manually or automate the process e.g. using curl or wget
Specify the Maven Install Plugin version in your pom
You are going to be relying on the Maven Install Plugin so you should install you specify the version in your pom.xml, rather than relying on the default version.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
</plugins>
</build>
Install the jar to your local repo
If the jar has been built with Maven, then it will include a pom.xml inside it. If you are unsure, open the jar with any archive manager and look inside the directory /META-INF/maven. You should find another directory named after the group ID, then another for the artifact ID, and then finally the pom.xml itself.
If the pom.xml is included, you can just run this and the tool will read the pom.xml to find the group ID and artifact ID so it can be placed in the right location in your repository:
mvn install:install-file -Dfile=/path/to/downloaded.jar
If the pom.xml is not included, you will need to specify all of this information yourself. It does not matter what you choose but you should choose something that isn't going to confuse you later:
mvn install:install-file -Dfile=/path/to/downloaded.jar -DgroupId=my-group-id -DartifactId=artifact-id -Dversion=some-version -Dpackaging=jar
Update your pom.xml
You can now just reference the dependency as normal in your pom.xml:
<dependency>
<groupId>my-group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>some-version</version>
</dependency>

Pom tag <finalName> is not working correctly

My project has pom.xml which builds up ear. I have added the finalName tag in pom.xml e.g. test-ear-${parent.version}-${region}. I am using following command -> mvn clean install -Dregion=QA. In my local workspace ear is formed with correct name as test-ear-3.5.23.0-QA.ear. However when it installs in the repository its build like test-3.5.23.0.ear. Means it is ignoring the finalName when installing in local repository.
What I understand is, maven is ignoring tag and using ArtifactName + Version to build name of artifact. Also I am not able to override version of artifact test-ear, because I suppose I am using the relative path in parent tag. Here is my sample pom.xml:-
<parent>
<groupId>com.proj</groupId>
<artifactId>test-parent</artifactId>
<relativePath>../test-parent/pom.xml</relativePath>
<version>${pom.version}</version>
</parent>
<groupId>com.proj.child</groupId>
<artifactId>test-ear</artifactId>
<packaging>ear</packaging>
<build>
<finalName>test-ear-${parent.version}-${region}</finalName>
<plugins>
<plugin>
.................
It works for me if I provide artifact version and versions of all the dependencies for test-ear artifact. Can someone guide, what is wrong with my pom.
Where is the properties label? you must put the field in this label,then get it use ${fieldname}.

Eclipse - Maven dependency is being ignored

I have a problem with adding maven dependencies to eclipse.
What should be OK:
pom.xml already contains all the dependencies and compilation and running tests using maven finished with success
all the source folders were recognized by eclipse
eclipse has Maven plugin and project is managed as maven project (see figure below)
pom.xml has maven-compiler-plugin, so the eclipse should know it is a maven project
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Issue:
eclipse does not resolve dependencies defined in pom.xml (guava, juint and other libraries are in pom.xml but not in eclipse class path)
any right click > Maven > Update project has no any effect (see figure below)
I noticed that libraries does not contain any Maven Managed Dependencies - by adding as described below has no any effect
My attempt to add Maven Managed Dependencies to Eclipse manually
1) Add library
1)
This attempt has no any effect and "Java Library Path" remains the same even after this action.
2)
Command
mvn eclipse:eclipse
Fails with
[ERROR] Failed to execute goal on project pmml-model: Could not resolve dependencies for project org.jpmml:pmml-model:jar:1.3-SNAPSHOT: The following artifacts could not be resolved: org.jpmml:pmml-agent:jar:1.3-SNAPSHOT, org.jpmml:pmml-schema:jar:1.3-SNAPSHOT: Could not find artifact org.jpmml:pmml-agent:jar:1.3-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots) -> [Help 1]
The jar does not exist in the desired version on the server your maven script is referencing. The most recent version is 1.2.9. The snapshot version is not present. You should reference
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.2.9</version>
</dependency>
in your pom.xml.
The below jars are not present in your remote repo.
org.jpmml:pmml-agent:jar:1.3-SNAPSHOT,
org.jpmml:pmml-schema:jar:1.3-SNAPSHOT
Open the url https://oss.sonatype.org/content/repositories/snapshots in your browser to see the available snapshots/
Apparently, you are trying to set up a project that makes use of the JPMML-Evaluator library. In that case, you should only depend on the latest stable org.jpmml:pmml-evaluator dependency (which is version 1.2.13 at the moment). In other words, don't try to manage the associated org.jpmml:pmml-model, org.jpmml:pmml-schema dependencies manually.
You could base your work on the JPMML-Evaluator-Bootstrap project instead.

How to skip lifecycle phase in multi maven module

I have a maven multi module project which call two sub modules. please note that this child module do not use the parent markup tag. Now I need to have the deploy phase executed only on one child module but not the other one. Could someone provide any advice on the best way of doing this ?
Thanks
As mentioned in this FAQ for maven deploy plugin, as well as in this SO discussion, you should add the following in the pom of the module you do not want to deploy.
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
you can go into the directory of the submodule and execute the goal there.
it is also possible to execute a specific module from the 'parent' with the --also-make option. see http://maven.apache.org/guides/mini/guide-multiple-modules.html
multiple-module maven project can specify on which submodule to execute phases with parent pom.xml.
Go to where the parent pom.xml is
execute: mvn --projects [target-module-artifactId] [phase/goal]. For example: mvn --projects submodule1 deploy

artifactory-maven-plugin: How to resolve dependencies from private Artifactory without settings.xml

How can I configure the artifactory-maven-plugin to resolve dependencies from our private Artifactory server?
The official documentation explains on how to publish:
https://www.jfrog.com/confluence/display/RTF/Maven+Artifactory+Plugin#MavenArtifactoryPlugin-Usage
Usually, dependency resolving works by adding servers to my .m2/settings.xml and specifying credentials there. However, in a cloud Docker build environment, it is difficult to place the settings.xml inside the container. It would be much easier if the plugin could be configured accordingly.
The Gradle Artifactory Plugin has explicit documentation about this (see dependencies resolution):
https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin#GradleArtifactoryPlugin-UsingtheArtifactoryPluginDSL
Turns out the Maven plugin also has a resolver configuration option. But it is not documented anywhere. This does not work (Maven still won't try to download dependencies from Artifactory):
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.6.1</version>
<inherited>false</inherited>
<configuration>
<resolver>
<contextUrl>${artifactory.context.url}</contextUrl>
<username>${artifactory.username}</username>
<password>${artifactory.password}</password>
<repoKey>libs-local</repoKey>
</resolver>
</configuration>
</plugin>
You can configure Maven to resolve artifacts through Artifactory you need to modify the settings.xml. You can generate one automatically, or modify it manually.
jfrog docs has provided steps to do this ,
In the Artifact Repository Browser of the Artifacts module, select Set Me Up. In the Set Me Up dialog, set Maven in the Tool field and click "Generate Maven Settings". You can now specify the repositories you want to configure for Maven.
Check here

Categories