Multiple-artifact resolution with Ivy - eclipse

I need to resolve a jcuda native library via Ivy, but I'm having some trouble finding the right way to define the dependency.
I'm using Artifactory for my dependency management, and it properly identified and resolved the individual native library versions for all available plaforms (see screenshot):
However, I am stuck at the resolution of the
The error produced by Ivy shows the correct resolution path.

I found a hint in the original Maven definition for these libraries (found in my local Ivy cache, %HOME%\.ivy2\cache\org.jcuda\jcuda-natives\windows-x86_64\ivy-0.8.0.xml.original), which used the following classifier:
<classifier>${jcuda.os}-${jcuda.arch}</classifier>
In my Ivy configurations, I don't distinguish OS and architecture, but using the catenated classifier gives me windows-x86_64, which is the jar file I'm looking for.
I needed to add the Maven namespace (xmlns:maven="http://maven.apache.org") to ivy.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" xmlns:maven="http://maven.apache.org">
And then the following dependency can use maven:classifier to resolve the specific native library I'm looking for:
<dependency org="org.jcuda" name="jcuda-natives" rev="0.8.0">
<artifact maven:classifier="windows-x86_64" ext="jar" />
</dependency>

Related

How to use maven to generate different artifactID with different scala version?

I'm writing a library for scala 2.10 and scala 2.11.
When I install this library to maven local repository or publish to maven central. I want the artifactID of the library to have different suffixes, e.g. like:
org.apache.spark:spark-core_2.10:1.6.3 &
org.apache.spark:spark-core_2.11:1.6.3
This is easy in sbt, but my project is built in maven.
Is there a plugin that allows me to add the suffix to my artifactID easily according to different maven profile? So I can install and publish 2 different versions from a single project codebase.
Thanks a lot for your opinion!
I do this using Maven properties, e.g.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<name>my-package</name>
<version>1.2.3</version>
<artifactId>${project.name}_${scala.compat.version}</artifactId>
...
</project>
You can set the scala.compat.version property either directly in the POM (if you only want one version), or in profiles (if you want to choose between multiple):
<properties>
<scala.compat.version>2.12</scala.compat.version>
</properties>
You can also specify it manually via the CLI, like mvn -Dscala.compat.version=2.12 package
Using the same property in your dependencies will ensure they match the chosen Scala version, e.g.
<dependency>
<groupId>org.typelevel</groupId>
<artifactId>cats-core_${scala.compat.version}</artifactId>
<version>2.1.1</version>
</dependency>
Note that this isn't ideal, since it generates the following Maven warning:
[WARNING] Some problems were encountered while building the effective model for org.example:my-package_2.12:jar:1.2.3
[WARNING] 'artifactId' contains an expression but should be a constant. # org.example:${project.name}_${scala.compat.version}:1.2.3, /private/tmp/nix-build-my-package_2.12-1.2.3.jar.drv-0/my-package-src/pom.xml, line 6, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

How to do a modular project architecture with Maven in Eclipse?

First of all im a little newbie in Maven+Eclipse world, so please excuse me if im not explaining myself good.
Im trying to implement Maven to existing Java old projects, the architecture im trying to achive is something like this (i put an image to explain myself a little better):
The project Utils have the most of the libs, that genericlly will be used for the other projects, and some classes that will be useful for the others (like date comparison method and mathematic method etc...), this project is working well with mvn install, generating the respective .war file.
The questions are:
The N Web Modules projects must have the project Utils as a
depedency and the most of dependencies too. I
don't know how to achive this in the pom.xml of N Web Modules
projects.
I don't know if it is posible in
Eclipse+Maven: Try to do some Parent Web Project that
implements the other projects and in one single mvn install the
parent project build and install the rest of the childs
(including Utils and N Web Modules).
I hope you can orientate and help me with this.
I think you are looking for Multi-Module projects
http://books.sonatype.com/mvnex-book/reference/multimodule.html
You can put various subprojects in one larger project and build them all at once. Furthermore, modules can depend on other modules (as long as this is not circular) and they are build in the correct order.
The project Utils have the most of the libs, that genericlly will be
used for the other projects, and some classes that will be useful for
the others (like date comparison method and mathematic method etc...),
this project is working well with mvn install, generating the
respective .war file.
One advise, you should extract classes used by other projects in a maven project with a JAR packaging and not leave them in a WAR packaging.
In Maven, generally, dependencies are provided as JAR.
It may also be provided as WAR by configuring the maven-war-plugin with some specific properties such as attachClasses but it looks like a trick and it also may create side effects.
Here are some information on how to do it.
But the documentation doesn't advise this way :
If you need to re-use this JAR/WAR in another project, the recommended
approach is to move the classes to a separate module that builds a
JAR, and then declare a dependency on that JAR from your webapp as
well as from any other projects that need it.
About your two questions.
The N Web Modules projects must have the project Utils as a dependency
and the most of dependencies too. I don't know how to achive this in
the pom.xml of N Web Modules projects.
Just include it as a dependency in the dependencies element of the consumer project :
<?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>mygroup</groupId>
<artifactId>project1-consumer</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
...
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
</dependencies>
</project>
I don't know if it is posible in Eclipse+Maven: Try to do some Parent
Web Project that implements the other projects and in one single mvn
install the parent project build and install the rest of the childs
(including Utils and N Web Modules).
What you are looking for is designing a multi-module project.
It relies on a aggregator pom that declares each module.
Note that this module has to be specified with a pom packaging as it doesn't produce a consumable artifact.
You could define something like that :
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>myaggregatorpom</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>util</module>
<module>project1-consumer</module>
<module>project2-consumer</module>
</modules>
</project>

Ivy + eclipse runtime dependencies deployment

I have an eclipse project with IvyDE managed dependencies
My IvyDE is something like:
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="R01"
module="myModule"
status="integration">
</info>
<configurations>
<conf name="compile" description="Used only at compile time; not deployed to the server" />
<conf name="runtime" extends="compile" description="Deployed to the server"/>
</configurations>
<dependencies>
<dependency org="com.sun.jersey" name="jersey-core" rev="1.9.1" conf="runtime"/>
<dependency org="javax.ws.rs" name="jsr311-api" rev="1.1.1" conf="compile"/>
</dependencies>
</ivy-module>
I have dependencies needed at compile-time and dependencies needed at runtime
I don't know if this is possible with apache IVY in eclipse (IvyDE) but I want to deploy to the server ONLY the RUNTIME-dependencies.
Now the only solution I've found is:
set IvyDE to resolve ALL (compile + runtime) dependencies and set the module classpath
add the [Ivy] library to the [DeploymentAssembly] at the project properties
This way all the dependencies (including the compile-time dependencies) are deployed to the server...
Is there any way to achieve this???
Thanks in advance
I answer my own question.
Finally I managed to get have TWO different ivy-managed classpath libraries, one used at compile-time and the other at run-time
The trick is include TWO ivyDE-managed dependencies:
One ivyDE managed dependency should be for COMPILE configuration and the other for RUNTIME configuration:
(repeat for the RUNTIME configuration)
Then it's only a matter of setting:
ivy dependency for COMPILE config should be a [Project Library]
ivy dependency for RUNTIME config should be at [Deployment Assembly]
That's all!

Performing substitutions in Eclipse product configuration file with tycho

I have a Eclipse RCP product which I build with Tycho. After some smaller issues, this is working pretty fine and I have both CI and releases as wanted.
The product in question is provided both as an installable stand-alone RCP application and as an update site so the functionality can be installed in a vanilla Eclipse installation. This works fine as well.
The product have a main feature - which is used on the update site - and I would very much like the feature and the product to have the same version number. As it is today, this version number is mentioned is many places and I would really like to reduce this to just one. I currently have the version number in
the feature.xml of the main feature
the pom.xml of the same feature
the .product file for the product configuration file
the pom.xml of the project with the .product file
the categories.xml file of the update site
the about.mappings file
I have tried to use maven resource filters and that works for the POM files and about.mappings, but not for the rest. This is my current pom.xml for the main feature:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<artifactId>...main.feature</artifactId>
<version>${product.version}-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
<parent>
<groupId>...</groupId>
<artifactId>...parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../...parent</relativePath>
</parent>
<build>
<!-- Substitutions: product.version -->
<resources>
<resource>
<directory>.</directory>
<includes>
<include>feature.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
When running this configuration, I get the following exception from Tycho (or an exception that looks very similar to it):
[ERROR] Internal error: java.lang.IllegalArgumentException -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.IllegalArgumentException
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:168)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
Caused by: java.lang.IllegalArgumentException
at org.eclipse.equinox.internal.p2.metadata.VersionParser.parse(VersionParser.java:93)
at org.eclipse.equinox.p2.metadata.Version.create(Version.java:79)
at org.eclipse.tycho.p2.impl.publisher.FeatureDependenciesAction.getVersion(FeatureDependenciesAction.java:126)
at org.eclipse.tycho.p2.impl.publisher.AbstractDependenciesAction.perform(AbstractDependenciesAction.java:79)
... 11 more
(I have cut some lines...)
Basically, the embedded maven process seems to not perform the resource filtering at all for this type of packaging. Or??
I have tried many different things, but I cannot get it to work. My best guess is that I have to configure the lifecycle, but how...
Can anybody help me with this?
this is a known bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=362252
You don't need to specify versions explicitly in the categories.xml. Just specify 0.0.0 as version, and Tycho will replace it by the actual version of the included feature.

Module dependency has friend dependency on org.netbeans.libs.javacimpl/1but is not listed as friend

I am developing some application on NetBeans Platform 6.9.1 with Maven. I have Netbeans Platform Application created from maven artefact. I need to depend on Java Source API, because my application is performing some kind of analysis on the source code of Java projects.
I have followed partially this tutorial: http://platform.netbeans.org/tutorials/60/nbm-copyfqn.html (with the exception, that I tried to do dependency management with Maven).
When I try to satisfy all dependencies (add them to pom.xml), I get this message:
Module dependency has friend dependency on org.netbeans.libs.javacimpl/1but is not listed as friend.
For javacimpl package (it's requested by the application that starts up)... the same error it writes for another two packages...
I have read many discussions in other forums, but none of them gave me clear solution.
Does anyone know?
In your module.xml you have to define an impl dependency
Have a look at the codehause page It would be better if you could use a spec dependency, but I have a feeling you wont be able to.
As an example your module.xml will look like this
<?xml version="1.0" encoding="UTF-8"?>
<nbm>
<licenseName>Apache License, Version 2.0</licenseName>
<licenseFile>license.txt</licenseFile>
<dependencies>
<dependency>
<id>org.netbeans.api:org-netbeans-modules-java-source</id>
<type>impl</type>
<explicitValue>0.60.2.10.8.4</explicitValue>
</dependency>
</dependencies>
</nbm>