Wrap groupId value in maven dependency specification - java

I am trying to add log4j-rolling-appender library as a dependency in my application. The jar is available here:
https://mvnrepository.com/artifact/uk.org.simonsite/log4j-rolling-appender/
I have added the following 2 things( repository and jar specification) in pom.xml. snippet below:
<?xml version="1.0" encoding="UTF-8"?>
<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>
...
...
<repositories>
<repository>
<id>log4j-appender</id>
<name> Repository for log4j-rolling-appender</name>
<url>https://mvnrepository.com/artifact/</url>
</repository>
</repositories>
<dependency>
<groupId>uk.org.simonsite</groupId>
<artifactId>log4j-rolling-appender</artifactId>
<version>20131024-2017</version>
</dependency>
...
...
</project>
Upon building, maven generates the following URL to download the dependency which is incorrect( Though as per the standards, it is correct however incorrect in my case):
https://mvnrepository.com/artifact/uk/org/simonsite/log4j-rolling-appender/20131024-2017/log4j-rolling-appender-20131024-2017.pom
Notice how the package mentioned in groupId(uk.org.simonsite) is converted to package hierarchy in the URL (../uk/org/simonsite/).
The URL where the JAR can be found and i want maven to generate is:
https://mvnrepository.com/artifact/uk.org.simonsite/log4j-rolling-appender/20131024-2017/log4j-rolling-appender-20131024-2017.pom
Can someone provide any suggestion on how do i instruct maven to skip this conversion while generating the URL ?

Maven repositories have a fixed format for resolving Maven coordinates.
After the starting URL, there is the groupId with / instead of ., then the artifactId, then the version, and then a filename that contains artifactId, version, classifier if present and the extension.
If you want to draw a jar from a different URL, then this URL is not a Maven repository. You should download the jar first and install it into your company repository (or your own local repository, if nothing else is available).

If you have using multiple dependencies then you should try using annotation wrapping all dependencies.
Also follow the pattern :
<project>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
<type>bar</type>
<scope>runtime</scope>
</dependency>
<repositories>
<repository>
<id>my-internal-site</id>
<url>http://myserver/repo</url>
</repository>
</repositories>
...
</project>
Dependencies with the scope system are always available and are not looked up in repository. Always use dependencies first before repository in order.

Related

Publish artifact to local maven repo with SBT and use it in Gradle project

Here is what I want to do:
In my Scala sbt project, I want to publish an artifact to my local maven repository
Afterwards, I want to use this artifact in a Gradle-based Java project
Here is where I struggle:
I have published the artifact somewhat successful using sbt publishM2. Here is my build.sbt:
organization := "com.example"
name := "my.messaging"
version := "0.1"
scalaVersion := "2.12.8"
publishMavenStyle := true
This generates the artifact here:
C:\Users\BAIERLF\.m2\repository\com\example\my-messaging_2.12\0.1
The POM file looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-messaging_2.12</artifactId>
<packaging>jar</packaging>
<description>my.messaging</description>
<version>0.1</version>
<name>my.messaging</name>
<organization>
<name>com.example</name>
</organization>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.8</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>ArtimaMavenRepository</id>
<name>Artima Maven Repository</name>
<url>http://repo.artima.com/releases/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
I find myself unable to successfully use this artifact in my Gradle project. This is how I tried to link it:
dependencies {
compile group: 'com.example', name: 'my-messaging_2.12', version: '0.1'
}
I feel like I am doing multiple things wrong here, but if anyone could give me a hint that would be great.
Edit: I tried it again with a slightly different result, so I updated my answer.
I had a similar problem recently, and solved it by adding a mavenLocal() command to my build.gradle file. I don'y know if you have the same issue, but it might be worth doing a build of your gradle project with full debug output and confirm it's attempting to pull from your local repo.

Basic maven question: Does maven transitively install dependencies?

I've looked here https://blog.packagecloud.io/eng/2017/03/09/how-does-a-maven-repository-work/ and that does seem to be the case.
However, I tried to experiment with mvn install and I'm not sure if it's worked as expected. Here's what I did
(1) I created a lib.
(2) Ran mvn install from the command line
(3) Copied the path of my newly created jar
(4) Opened a new maven project, stuck the path into my pom.xml
I'm able to reuse my library methods, BUT: one of my library methods returns a TransportClient which is part of the elasticsearch api. Using intellij inside my new project, it seems like I don't have elasticsearch even though I'm referencing the jar.
Is this expected? I was expecting it to have transitively installed elasticsearch when it referenced my jar.
I'd love a pointer or two in the right direction, I'm completely new to this. :)
My pom.xml for the lib that uses elasticsearch as dependency.
<?xml version="1.0" encoding="UTF-8"?>
<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>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>estutorial</groupId>
<artifactId>estutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.4.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
</dependencies>
</project>
My pom.xml for the new maven project that tries to reference the lib for the above pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<groupId>sth</groupId>
<artifactId>sth</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>estutorial</groupId>
<artifactId>estutorial</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>/home/dell/.m2/repository/estutorial/estutorial/1.0-SNAPSHOT/estutorial-1.0-SNAPSHOT.jar
</systemPath>
</dependency>
</dependencies>
</project>
So, if I understand your steps, your dependency declaration in your referencing application uses a direct classpath to the jar file in your local repository? If so, this is unusual. You shouldn't need to know direct file locations for any of your dependencies of a Maven project. What you should be doing.
In the referenced project (that which requires the Elasticsearch library), it's pom.xml file would defined the elasticsearch dependency itself. This should follow maven standards for dependency declaration (groupId, artifactId and artifactVerion). If you don't have the elasticsearch artifact, maven will attempt to find it and store it in your local repository. You shouldn't have to have any path in your pom.xml file.
When you install the referenced project, it will install into your local repostory both the JAR file and the pom.xml.
In the referencing project, you should define the dependency to your referenced artifact in it's pom file. Same format: groupId, artifactId and artifactVersion. You shouldn't need to provide a specific path. What maven will do is find your referenced jar, but also use the installed POM.xml file for the referenced jar to find the transitive dependencies and include them in your classpath.
From what you've described, your dependency declarations aren't correct. If you can provide your POM file more details can be provided. Otherwise, review the maven intro to dependencies.
No. mvn install is a nearly useless command. It stuffs a jar file into your local repository, for subsequent use by other maven builds. You use the term 'path'. If you run mvn install:install-file to put a jar into your local repo under some coordinates, you can reference those coordinates from another pom; but it will generally lead to future problems as compare to deploying the jar into a proper repository manager.

Trying to use maven with android eclipse project not working?

This is the first time I've used maven, I am trying to integrate zopim sdk and I followed the tutorial and converted my project to a maven project and added the repository and dependencies, but now eclipse does not compile and gives me the following error :
Description Resource Path Location Type
Missing artifact com.android.support:appcompat-v7:jar:23.0.0 pom.xml /4SaleApp line 2 Maven Dependency Problem
Missing artifact com.android.support:design:jar:23.0.0 pom.xml /4SaleApp line 2 Maven Dependency Problem
Missing artifact com.android.support:recyclerview-v7:jar:23.0.0 pom.xml /4SaleApp line 2 Maven Dependency Problem
What should I do ?
EDIT
my pom.xml file
<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>4SaleApp</groupId>
<artifactId>4SaleApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<repositories>
<repository>
<id>chatsdk-repo</id>
<name>Chat SDK Repo</name>
<url>https://zendesk.artifactoryonline.com/zendesk/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.zopim.android</groupId>
<artifactId>sdk</artifactId>
<version>1.1.0</version>
<type>aar</type>
</dependency>
</dependencies>
</project>
This seems like a conflicting issue when changing from Gradle to Maven. This questions provides a lot more info on the issue.
But it looks like you are missing the android support dependencies in the pom. Maybe try adding the missing support libraries to the pom. For example as shown here for appcompat-v7:
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>${compatibility.version}</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>${compatibility.version}</version>
<type>jar</type>
</dependency>

Gradle search dependency in repository from maven pom.xml

I have an Android library dependency which I pull in from my own Maven repository (Artifactory based):
compile "com.jmolsmobile.mylibrary:mylibrary:1.0.4"
This dependency depends on another library, which is located in another Maven repository with a custom URL:
repositories {
maven { url 'https://mint.splunk.com/gradle/' }
}
What I want to do is to include my Android library in another project, without having to add the repository URL explicitly to my Gradle files, but rather have my project inherit the repository URL via the Maven pom.xml.
But Gradle does not search in the custom repository URL:
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.splunk.mint:mint:4.2.1.
Searched in the following locations:
https://jcenter.bintray.com/com/splunk/mint/mint/4.2.1/mint-4.2.1.pom
https://jcenter.bintray.com/com/splunk/mint/mint/4.2.1/mint-4.2.1.jar
http://10.0.190.250:8081/artifactory/android-snapshot-local/com/splunk/mint/mint/4.2.1/mint-4.2.1.pom
http://10.0.190.250:8081/artifactory/android-snapshot-local/com/splunk/mint/mint/4.2.1/mint-4.2.1.jar
file:/Applications/Android-SDK/extras/android/m2repository/com/splunk/mint/mint/4.2.1/mint-4.2.1.pom
file:/Applications/Android-SDK/extras/android/m2repository/com/splunk/mint/mint/4.2.1/mint-4.2.1.jar
file:/Applications/Android-SDK/extras/google/m2repository/com/splunk/mint/mint/4.2.1/mint-4.2.1.pom
file:/Applications/Android-SDK/extras/google/m2repository/com/splunk/mint/mint/4.2.1/mint-4.2.1.jar
Even though the repository is explicitly defined in my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.jmolsmobile.mylibrary</groupId>
<artifactId>mylibrary</artifactId>
<version>1.0.4</version>
<packaging>aar</packaging>
<repositories>
<repository>
<id>splunk</id>
<url>https://mint.splunk.com/gradle/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.splunk.mint</groupId>
<artifactId>mint</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>
</project>
Any ideas why this is going wrong?

How do I add the storm mongo library as a maven dependency?

I'm trying to use a SimpleMongoBolt from storm-contrib. I downloaded the source, entered the storm-contrib-mongo directory and ran mvn package and mvn install. Everything worked fine and IntelliJ was able to resolve things while coding. When I try to build my project, however, it tries to find a pom for this library on an external repository. When it can't find it, it fails. What do I need to do to fix this?
<?xml version="1.0" encoding="UTF-8"?>
<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>StormTest</groupId>
<artifactId>StormTest</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>StormTest</name>
<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.7.2</version>
<scope>Test</scope>
</dependency>
<dependency>
<groupId>com.rapportive</groupId>
<artifactId>storm-amqp-spout</artifactId>
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>com.rapportive</groupId>
<artifactId>storm-json</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>storm</groupId>
<artifactId>storm-contrib-mongo</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
You can try to check if you have proper dependencies defined in your project pom and compare them to storm artifact one. groupId, artifactId and version must be the same or Maven will try to download it from external repository and probably failed as it has never been installed on any public Maven repo.
When you install your artifact, it goes to user-directory/.m2/repostiory/group/id/path/*artifact/id/path*/version.
For your storm-amqp-spout you should have it in:
user-directory/.m2/repository/com/rapportive/storm-amqp-spout/0.1.1 folder.
There you should have few files:
jar itself (if it was packaged as jar file).
pom.xml file (the same you created for your project and you used to built and install it).
optionally sha1 files for both above.
If you don't have them, you probably made some mistake installing the artifact into repository. You can try to install it again or manually create pom just copying it from artifact source directory.
If there's correct pom.xml, I don't really have idea as I have never worked with IntelliJ (idea? ;)).
SimpleMongoBolt in Storm-Contrib was actually out of date. I updated the module myself and submitted a pull request, which has yet to be merged. Currently you can retrieve the updated code from my Storm-Contrib fork.

Categories