Project

General

Profile

Actions

How to Access a Maven Repository » History » Revision 10

« Previous | Revision 10/26 (diff) | Next »
Henning Blohm, 26.03.2014 16:59


Maven Repos Support

The main idea behind this concept is to hook existing Maven repositories in as component repositories. At first this is most useful for libraries, later this may be extended to other archetypes.

Maven repository suppport can be implemented in z2-base and does not require core changes.

Principles

The main idea is that based on some root artifacts and some maven remote repository configuration, jar artifacts and dependencies will be made available as Java component in Z2 that can be referenced or included as suits best.

Name mapping and version resolution

Artefacts in Maven repos have a fully qualified name of the form

<groupId>:<artifactId>:<version>

or

<groupId>:<artifactId>:<packaging>:<version>

By default, a jar artifact <groupId>:<artifactId>:<version> will result into a Java component of name

<groupId>:<artifactId>/java

Given that the resolution of the root artifacts and dependencies lead to artifacts of the same packaging, group id, and artifact id but with different versions the higher version number will be used (but see #1695).

Example configuration

A maven repository component may look like this:

com.zfabrik.systemStates.participation=com.zfabrik.boot.main/sysrepo_up
com.zfabrik.component.type=com.zfabrik.mvncr
mvncr.priority=200
mvncr.roots=\
    org.springframework:spring-context:4.0.2.RELEASE,\
    org.springframework:spring-aspects:4.0.2.RELEASE,\
    org.springframework:spring-tx:4.0.2.RELEASE,\
    org.springframework:spring-orm:4.0.2.RELEASE,\
    org.springframework:spring-web:4.0.2.RELEASE,\
    org.springframework.security:spring-security-core:3.2.2.RELEASE,\
    org.springframework.security:spring-security-web:3.2.2.RELEASE,\
    org.springframework.security:spring-security-config:3.2.2.RELEASE,\
    org.springframework.security:spring-security-aspects:3.2.2.RELEASE,\
    org.hibernate:hibernate-entitymanager:4.3.4.Final,\
    aopalliance:aopalliance:1.0,\
    org.aspectj:aspectjweaver:1.7.4,\
    org.aspectj:aspectjtools:1.6.9,\

mvncr.excluded=\
        org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec

mvncr.managed=\
        commons-logging:commons-logging:1.1.2

By default, all non-optional compile scope dependencies will be resolved. The resulting Java component will have the target artifact as API library and all non-optional compile scope dependencies as public references in their mapped form.

The z2 core will use lazy component class loaders to make sure that use of include libraries has virtually no runtime penalty.

Fine-Tuning of the Dependency Graph

In order to deviate from the default resolution and mapping, maven repository roots may be specified with a query string like this:

    org.springframework.security:spring-security-aspects:3.2.2.RELEASE?versioned=true&scope=RUNTIME&excluded=commons-logging:commons-logging:1.1.2

versioned: If set to true, the version part will not be removed from the java component name mapping and instead a versioned name is used. That is, in the case above, a java component org.springframework.security:spring-security-aspects:3.2.2.RELEASE/java would be mapped. This is useful if "non-default" versions are required.

scope: Any of RUNTIME, COMPILE, PROVIDED, SYSTEM, TEST. Conforms to the corresponding Maven dependency scopes. If set, non-optional dependencies of the respective scope will be traversed to resolve dependencies.

excluded: Exclusions on the dependency graph.

Handling the impact of PROVIDED references

At times, Maven provided artifacts require the presence of artifacts on the classpath that are expected to be required by the environment - most typically this is true for Web framework w.r.t the Servlet API.

In that case, it is simplest to create a Z2 project representation that includes all related artifacts (or include directly). In order to simplify this include process, includes may be specified to be transitively following Java component references by adding a corresponding query modifier to the include definition:

java.publicIncludes=\
    com.vaadin:vaadin-server?expand=true

References

To Dos

  1. Handling of SNAPSHOT-Versions to be revisited

Updated by Henning Blohm over 10 years ago · 10 revisions