Ivy not downloading secondary dependency on Jar - maven

We are having a bit of a transitive issue between Ivy and Maven:
We have a project called ivylib. Ivylib is an Ant/Ivy project that depends upon another project called mvnlib.
Mvnlib depends upon another project called jersey-client. This in turn depends upon jersey-core. Both of these are part of the com.sun.jersey groupId.
In the Mvnlib pom.xml file, we have the following dependency:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
Looking at the jersey-client project, I see the following dependency in its pom.xml file:
<profiles>
....
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
In the ivy.xml file of the Ivylib project, we have the following dependency:
<dependency org="com.travelclick" name="ivylib"
rev="2.1" conf="compile->default"/>
All dependencies of Mvnlib are downloaded and included in Ivylib except for the secondary dependency of the jersey-core jar.
I suspect it has something to do with this dependency being inside a <profile> dependency rather than being listed in the file itself. I was wondering if there's anyway to get the core jar to download.
For now, we simply inlcude the jersey-core jar in our Mvnlib project, but I was wondering if there's another way.

Best thing to do is to check your cache location for your IVY resolve. Once I looked at the dependency list for jersey-client, I noticed that "jersey-core" is not one of them. See below the ivy-1.19.xml file generated from the POM:
<dependencies>
<dependency org="junit" name="junit" rev="4.8.2" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="com.sun.net.httpserver" name="http" rev="20070405" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="org.osgi" name="osgi_R4_core" rev="1.0" force="true" conf="provided->compile(*),provided(*),runtime(*),master(*)"/>
...
</dependencies>
I would just add another dependency to my Ivy file. Copy/Paste the "jersey-cleint" dependency line and change to "jersey-core". It would be nice if the POM had "jersey-core" listed properly though wouldn't it? :-)

Related

How to add craftbukkit to minecraft 1.19.3 plugin as dependency?

I am trying to update a plugin [in 1.18.2] that I haven't written myself to minecraft 1.19.3.
However I am struggling with figuring out how to add craftbukkit as a dependency. I use maven and it seems to be unfindable for 1.19.3 in the mvnrepository.com. Further investigation led me to buildtools, which I ran and it did give me several folders and jar files, one of which is craftbukkit, spigot and bukkit.
However trying to add those jar files as dependencies also gave me errors of referencing to a non-existing file. Even though the file does exist in the resource folder of the project.
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>/GUIMarketplaceDirectory-master/src/main/resources/craftbukkit-1.19.3.jar</systemPath>
</dependency>
I also tried changing the path to start at my very source folder, but this didn't work. Any help would be appreciated.
I'm not sure you can add CraftBukkit as a dependency. It needs to be either bukkit, or spigot, since CraftBukkit is a server mod, not the plugin API. Here is code for a Spigot import.
<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

Maven POM packaging with dependencies

I'm trying to construct a codebase where subsystems can be developed as maven modules, without the importing POM needing to concern itself with the internal structure of the maven module.
The "importing" pom
<project>
<artifactId>application</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<artifactId>submodule-1</artifactId>
</dependency>
</dependencies>
</project>
The "imported" pom
<project>
<artifactId>submodule-1</artifactId>
<packaging>pom</packaging>
<modules>
<module>api</module>
<module>implementation</module>
</modules>
<dependencies>
<dependency>
<artifactId>api</artifactId>
</dependency>
<dependency>
<artifactId>implementation</artifactId>
</dependency>
</dependencies>
</project>
This does seem to work, at least partially; the generated JARs appear to be on the classpath during mvn package. IntelliJ shows the application has a dependency on submodule-1 and transitively on api and implementation. However, mvn dependency:tree fails while building submodule-1 saying
Could not resolve dependencies for project submodule-1:pom:1.0.0-SNAPSHOT: Could not find artifact api:jar:1.0.0-SNAPSHOT
I'm trying to determine if this is a valid pattern, that of having packaging of pom, with defined dependencies which are also defined modules in the POM.
Have I stumbled upon a working-but-not-supported edge case, or is the dependency plugin broken in some way, or I'm breaking it in some way, or something else?

Prevent maven-shade-plugin from exposing <system> dependency?

Thanks to a separate thread, I realized my project's uber-jar had a bug. I create the uber-jar using maven-shade-plugin because I need the more advanced transformer capabilities to merge several ServiceLoader definitions.
So, the issue is that my project has a system-scope compile-time dependency on tools.jar, locating tools.jar on the local machine relative to the value of the java.home sysprop. The bug is that I didn't realize this dependency was:
leaking into the dependency-reduced pom.xml of the uber-jar, and
even worse, the pattern ${java.home} in the dependency definition was being resolved and hard-coded into the uber-jar's POM. This second part was particularly embarrassing as it reveals the JDK location of the build machine (see line 50 here).
To workaround this problem, I conditionally disabled the profile which created the dependency. All details below are in the <activation> section:
Before:
<profile>
<id>internal.tools-jar</id>
<activation>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
After:
<profile>
<id>internal.tools-jar</id>
<activation>
<jdk>1.8</jdk>
<file>
<missing>src/main/java/systems/manifold/Dummy.java</missing> <!-- this file is only present in the uber-jar module, therefore exclude if present -->
</file>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
So, after all that, my question is: is this the best way to prevent this system-scoped dependency from leaking into the uber-jar's dependency-reduced pom.xml?
Thanks in advance,
Kyle
Updated 2018-02-16:
Unfortunately the following configuration in the shade plugin doesn't prevent the system-scope dependency from leaking:
<artifactSet>
<excludes>
<exclude>*</exclude>
</excludes>
</artifactSet>
to the shade plugin's configuration but the resolved system scope dependency still shows up in the POM. Puzzling!

Maven projects - how to read a property that is defined in the pom file of a project that is added as a dependency

I am working on a large project that contains many maven projects. We are using Maven 3.3.9.
I want to use a property that is defined in one maven project in another project, but i can't access the property.
The situation is: there is one maven project called "product-packaging", that has a pom file that includes some properties. This maven project only contains a pom file. It is used for generating a package that contains a set of components that are compatible with each other.
There is another maven project called "projectX" that has a dependency on "product-packaging". In "projectX" we want to use a property that is defined in "product-packaging".
I want to add xx-ws-rest as a dependency in projectX, and i want to set the version as xx-ws-rest.version, which is a property that is defined in "product-packaging"
The pom of "product-packaging" looks like:
<project ...>
...
<properties>
<xx-ws-rest.version>1.6.0</xx-ws-rest.version>
</properties>
...
</project>
The pom of "projectX" looks like:
<project ...>
...
<properties>
<product-packaging.version>1.6.0</product-packaging.version>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>product-packaging</artifactId>
<version>${product-packaging.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.company.product.xx</groupId>
<artifactId>xx-ws-rest</artifactId>
<version>${xx-ws-rest.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.company.product.xx</groupId>
<artifactId>xx-ws-rest</artifactId>
<type>war</type>
</dependency>
....
</dependencies>
</project>
AFAIK this is not possible. The usual way to define common properties for different projects is to use a parent POM. There, you can define properties and let the different projects inherit from that parent POM - that way, the properties are visible for all child projects.

maven profile question

I am new to Maven and I have very basic question. I have one J2EE app(EAR). When I build this app I want to ignore some dependency in lib folder of my war as this jars will be provided by my server like jboss(all hibernate stuff). But when I run this war project inside embedded jetty server then I need it to be inside my lib folder. I heard about the maven profile which can be used for similar purpose. Can somebody give me an example or some detail about it or is there some other way to achieve this task. I have an EAR which contains ejb module(jar) and web module(war).
Thanks
Specify your library in a profile. Set <scope>provided</scope> for your library in a jboss profile. E.g.:
<profiles>
<profile>
<id>jboss</id>
…
<dependencies>
<dependency>
<groupid>...</groupid>
<artifactid>...</artifactid>
<version>...</version>
<scope>provided</scope>
</dependency>
</dependencies>
…
</profile>
<profile>
<id>jetty</id>
…
<dependencies>
<dependency>
<groupid>...</groupid>
<artifactid>...</artifactid>
<version>...</version>
</dependency>
</dependencies>
…
</profile>
</profiles>

Resources