Maven local artifactory file edit - java

I have uploaded some of the jars to the my local artifactory...
For a example....
Repository Browser
+--org
|-jboos
|-json
|json-java
|-maven-metadata.xml
This xml file Dependency Declaration shown as below
<dependency>
<groupId>org</groupId>
<artifactId>json</artifactId>
<version>json-java</version>
<type>xml</type>
</dependency>
I need to change this xml file for a reason. Is there anyway to do this artifactory UI itself. (Without login to the locale artifactory server )

First, do not upload maven-metadata files. They are generated by Artifactory for you.
Second, since Artifactory usually manages uneditable binary files, there is no edit functionality in Artifactory.
I am with JFrog, the company behind Bintray and [artifactory], see my profile for details and links.

Related

Why I got "Failed to transfer file RELEASE does not allow version" in Maven

My Maven project's structure like this:
testMaven(root)
--brother-module
--brother-grandson-module
--son-module
--grandson-module
Obviously my dependency of parent modules and children modules follows my file directory.
and when I compile or install the grandson-module,It's can be passed and successd.
but when I make grandson-module depend on brother-grandson-module
<dependencies>
<dependency>
<groupId>test.cx</groupId>
<artifactId>brother-grandson-module</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
and while show
Could not transfer artifact test.cx:brother-grandson-module:pom:1.0-SNAPSHOT from/to nexus (http://10.10.0.89:8088/nexus/repository/maven-releases/): Failed to transfer file: http://10.10.0.89:8088/nexus/repository/maven-releases/test/cx/brother-grandson-module/1.0-SNAPSHOT/brother-grandson-module-1.0-SNAPSHOT.pom. Return code is: 400 , ReasonPhrase:Repository version policy: RELEASE does not allow version: 1.0-SNAPSHOT.
and then after my install the brother-grandson-module,it will success again.
I wonder why cause it.please tell my why it works like this.Thanks.

Programmatically retrieve Maven Dependencies

Pls are there any Java libraries that can retrieve Maven dependencies from a POM file? Anything that does not require retrieving out put of a mvn command. Thanks
Well, you should parse the pom.xml with any xml parser of your choice.
Then construct the link to maven central repository by the following algorithm:
1. Each package in group id is translated to a folder:
Example:
<groupId>org.foo.bar</groupId> ==> org/foo/bar
Artifact name is also a folder and append it to the group id:
Example:
<artifactId>some-artifact</artifactId> ==> org/foo/bar/some-artifact
Version also becomes folder:
Example:
<version>1.2.3</version> ==> org/foo/bar/some-artifact/1.2.3
Now construct the jar name as "articatId-version.jar" and append it to the link.
Prepend the repository and you'll get a full-working path.
Here is a real working example:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
Gets translated to:
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/2.2.4.RELEASE/spring-boot-2.2.4.RELEASE.jar
As an alternative if you want some library that can work with dependencies don't want to call maven, take a look at Apache Ivy
Thanks.
I used the MavenProject library. Pretty straight forward.
I also used MavenXppReader to get the model that I passed to MavenProject(). The rest was a matter of calling the right methods.

Create side artifact from directory

I am currently writing a Maven plugin that creates some files in a subdirectory of target. My wish is to zip these files and deploy them as side artifact.
More precisely:
Say I have created some files in target/someplugin. Then I want to zip these files and attach them to the build, so that the zip is installed/deployed with classifier someplugin.
How can I achieve this?
I did the following (may not be perfect):
First I injected the MavenProjectHelper
#Component
private MavenProjectHelper projectHelper;
Then I added the zt-zip library
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-zip</artifactId>
<version>1.13</version>
<type>jar</type>
</dependency>
Now I can do something like
ZipUtil.pack(someplugindir, somepluginzip);
projectHelper.attachArtifact(project, "zip", "someplugin", somepluginzip);
and everything looks fine.

Add jar file to local repository (linux server)

I created a "lib" folder in my project
~\test2000\lib\ls-client.jar
Then, I added a jar file to this folder
Now I want to call him in the project, I did this with the following code, In my system right.
<dependency>
<groupId>com.lightstreamer</groupId>
<artifactId>ls-client</artifactId>
<version>2.5.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ls-client.jar</systemPath>
</dependency>
But when I transfer the program to the Linux server
There's an error saying that it can not read jarFile
I think I do not enter groupId and artifactId!!!
Can anyone help me?
step 1:
Download the "ls-client", extract it and copy the ls-client.jar to somewhere else, for example, c drive. Issue following command :
mvn install:install-file -Dfile=c:\\test2000\lib\ls-client.jar -DgroupId=com.lightstreamer
-DartifactId=ls-client -Dversion=2.5.2 -Dpackaging=jar
step 2:
<dependency>
<groupId>com.lightstreamer</groupId>
<artifactId>ls-client</artifactId>
<version>2.5.2</version>
</dependency>

Retrieving Maven Artifact from Repository using Maven Java API

If I have a Maven Artifact information (GroupId, ArtifactId, Version) how can I programmatically (using Java) retrieve that Artifact from my local repository?
Specifically, I need to be able to connect to the Maven Repository and create/retrieve a org.apache.maven.artifact.Artifact so I can retrieve the file associated with the Artifact.
I have looked into m2e source code, but the MavenImpl.java (which provides Artifact resolution) is way more complex than what I need and it is difficult to understand how the connection to the repository works.
You'll probably want to look at Aether. See the Wiki for examples.
You can construct a URL from the given information and download the file (note, replace the '.' in the <groupId> with '/'):
<repositoryUrl>/<groupId>/<artifactId>/<version>/<artifactId>-<version>.<type>
This is how we do it in jcabi-aether:
final File repo = this.session.getLocalRepository().getBasedir();
final Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
JavaScopes.RUNTIME
);
Give it a list of remote repositories, a location of a local repo, and Maven coordinates of the artifact. As the name shows, the library uses Apache Aether from Sonatype.

Categories