project.build.finalName is not working with deploy-file goal - maven

can we use project.build.finalName in the command line options of the mvn deploy:deploy-file goal.
here is my command:
mvn deploy:deploy-file -DgroupId=abc -Dproject.build.finalName=test -DartifactId=test -Dversion=1.0 -Dpackaging=jar -Dfile="file_path" -Durl=url -DrepositoryId=id`
the details are :
first, there is no POM file available.
i am just executing this command to upload the artifact in nexus.
now the issue is , the artifact being uploaded has the name as : ${artifactId}-${version}
and i dont want version in the finalname. i have alrady gone through the couple of posts and found that we can use project.build.finalName
but in this case , it is still uploading with version number. how can i fix that ?

You need to drop the -Dproject.build.finalName part and add -DgeneratePom=true instead, as you're already specifying the full path to the artifact via the -Dfile.
You cannot not have the version part when deploying to a Maven remote repository (which is what you're trying to do). When deploying to a Maven repository, your artifact's GAV (groupId, artifactId, version, type and classifier) coordinates will get translated into:
${groupId}/${artifactId}/${version}/${artifactId}-${version}.jar
For example, for these GAV-s:
groupId : com.foo
artifactId : bar
version : 1.2.3-SNAPSHOT
type : jar
classifier : [null, javadoc, sources]
You will get a path like:
com/foo/bar/1.2.3-SNAPSHOT/bar-1.2.3-SNAPSHOT.jar
com/foo/bar/1.2.3-SNAPSHOT/bar-1.2.3-SNAPSHOT-javadoc.jar
com/foo/bar/1.2.3-SNAPSHOT/bar-1.2.3-SNAPSHOT-sources.jar
The -Dproject.build.finalName is for cases, where you'd like the artifact to have a different name so that, (for example), your build process can use that for simplicity, or convenience.
If you're deploying using deploy-file and have no pom.xml file, your command-line should look something like this:
mvn deploy:deploy-file \
-DgroupId=com.foo \
-DartifactId=bar \
-Dversion=1.2.3-SNAPSHOT \
-Dpackaging=jar \
-Dfile="path\to\foo-1.2.3-SNAPSHOT.jar" \
-Durl=http://the-url-to-your-repository/ \
-DrepositoryId=the-repository-id-defined-in-your-settings.xml-that-has-your-credentials

Related

Maven Local file installation

I am trying to install a local jar file to be used as a dependency using the following command
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=<path-to-file>
Getting the following result
The goal you specified requires a project to execute but there is no POM in this directory
To install the file in the local maven repository, you have to provide also the group ID, artifact ID, and the version for that file. Without them, Maven does not know in what directory to store the file.
See also: https://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html.
Maven need the so called GAV coordinates: groupId, artifactId, version and packaging to store the artefact.
You can name them wiht the install command
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file
-Dfile=<path-to-file>
-Dpackaging=jar
-DgeneratePom=true
-DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version>

How to directly upload a jar file to nexus repository using maven without pom file or settings.xml file?

Context : I do not have UI access to Nexus Repository but I have access to Jenkins configured with access to nexus repository. I have a shaded jar in my git repository which needs to be directly uploaded to nexus repository using maven without pom.xml or settings.xml file.
Problem : How to upload a jar in git repo to nexus repository using Jenkins with maven plugin ?
I tried searching for this specific usecase and was not able to find a solution.
You can create a Jenkins Job to clone git repository [Source Code Management] where the required jar is present and configure Jenkins Job Build stage with below maven command [Execute Shell] :
mvn deploy:deploy-file \
-DgroupId=com.example.test \
-DartifactId=test-module \
-Dversion=1.0.0 \
-DgeneratePom=true \
-Dpackaging=jar \
-DrepositoryId=sample-rel \
-Durl=http://nexus.private.net/Your_Nexus_Repository_Path \
-Dfile=./PATH_TO_JAR_FILE
(edit: multi-line for legibility)
The deploy:deploy-file solution above still requires a settings.xml file. The login credentials will be retrieved from the setting.xml "servers" section using the ID specified in the repositoryId parameter. There isn't any way that I know of to deploy using Maven without a settings.xml file. But you can specify a custom settings.xml file with "mvn -s some/path/settings.xml".
Alternatively, you could use a Jenkins plugin to do the deploy: https://help.sonatype.com/integrations/nexus-and-continuous-integration/nexus-platform-plugin-for-jenkins#NexusPlatformPluginforJenkins-RepositoryManager3Integration

maven: local installed jar not found

I'm getting this error message:
Could not resolve dependencies for project com.psgd.template:backend:war:1.0.0: Could not find artifact com.oracle:ojdbc7:jar:12.1.0.2
I've previously installed this library into local repository using:
mvn install:install-file \
-DgroupId=com.oracle \
-DartifactId=ojdbc7 \
-Dversion=12.1.0.2 \
-Dpackaging=jar \
-Dfile=ojdbc7-12.1.0.2.jar \
-DgeneratePom=true
I've look up into my repository:
$ ls -Rh ~/.m2/repository/com/oracle/
/home/jeusdi/.m2/repository/com/oracle/:
ojdbc7
/home/jeusdi/.m2/repository/com/oracle/ojdbc7:
12.1.0.2
/home/jeusdi/.m2/repository/com/oracle/ojdbc7/12.1.0.2:
ojdbc7-12.1.0.2.jar.lastUpdated ojdbc7-12.1.0.2.pom.lastUpdated
So, it's present into local repository.
Any ideas?
Many things can go wrong here.
When you run mvn install:install-file you should see the log line in command line: something like : INFO Installing file ... to full <<PATH_COMES_HERE>>
So check that path.
If everything works as expected you should be able to see both pom.xml and the jar in the corresponding folder of your repository, not "lastUpdated" I believe.
I don't see it in the provided snippet...
You can also check permissions as one possible source of issues.
The last thing is checking the actual pom generated by install:install-file. Make sure, the pom is valid and contains the information you've entered.
You can also delete the whole folder from maven repo and re-run mvn install:install-file maybe the repo went corrupted for some reason who knows.
The files
ojdbc7-12.1.0.2.jar.lastUpdated ojdbc7-12.1.0.2.pom.lastUpdated
mean that the Maven looked for the pom and did not find it. It is a kind of cache for missing artifacts.
Please delete these two files and try again to install the jar. Then try again to build against it.

Maven create a project without sources

I'm currently trying to deploy a third party jar and 2 dlls to a private artifactory.
I don't have the sources for any of these artifacts. I could install these artifacts manually trough mvn install:install-file but I would have to manually do that every time the jar or dlls are updated.
I was trying to achieve a solution that allowed me to deploy with mvn deploy.
I was thinking about creating a maven project with these 3 artifacts or a parent maven project with 3 child project as dependency. What is the best way to create a maven project in this case where I have no source to compile and put in a jar file?
If you have the case where you three files belong to the same project which means jar file needs the dll's you should deploy them as a main artifact (jar) and supplemental artifacts (classifier) for the dll's which can be achieved by something like this:
mvn deploy:deploy-file \
-DgroupId=com.soebes.test \
-DartifactId=t1 \
-Dversion=1.0.1 \
-Dpackaging=jar \
-Dfile=t1.jar \
-Dfiles=t1.xml,t1.pdf \
-Dclassifiers=xml,pdf \
-Dtypes=xml,pdf \
-Durl=http://localhost:8081/nexus/content/repositories/releases \
-DrepositoryId=releases
Where file= is the main artiact and files=... the list of artifacts. The classifier is given for every artifact in the list given via files=....
The repositoryId is needed if you have authentication for your repository manager.

install maven archetype project jar with *.pom file to local repo

i`m kinda new to maven and want to know how to install an archetype jar to my local repo
i got a directory com.foo with the following files:
maven_metadata_local.xml
[1.00.00-SNAPSHOT]
which containes these files
_maven.repository
foo-archetype-1.00.00-SNAPSHOT.jar
foo-archetype-1.00.00-SNAPSHOT.pom
maven_metadata_local.xml
from what i read i understand that there is a way to build a template project using this archetype but first i need to install it to my local repo
how can i do this?
thanks
i managed to do that:
what i did is opened the maven_metadata_local.xml to get the groupId, artifactId, and version
run this command from that directory
mvn install:install-file
-Dfile=foo-archetype-1.00.00-SNAPSHOT.jar \
-DgroupId=com.foo \
-DartifactId=foo-archetype \
-Dversion=1.00.00-SNAPSHOT \
-Dpackaging=jar \
-DgeneratePom=true
once compleated (BUILD SUCCESS) i got the build in my local repository
go to a folder from which i want to create a project
run this command
mvn archetype:generate \
-DarchetypeGroupId=com.foo \
-DarchetypeArtifactId=foo-archetype \
-DarchetypeVersion=1.00.00-SNAPSHOT \
-DgroupId=com.mycom \
-DartifactId=myApp \
-Dversion=myversion-SNAPSHOT
in eclipse i imported an existing maven project, right click on the project->maven->update
and i got the full build ready to work
Adding an archetype to your local repository is no different than adding any other dependency. You can simply run a mvn install command on it.

Resources