How to Access a Maven Repository » History » Version 14
Henning Blohm, 26.04.2014 21:20
1 | 11 | Henning Blohm | h1. Maven Repos Support (#1696) |
---|---|---|---|
2 | 1 | Henning Blohm | |
3 | 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. |
||
4 | |||
5 | Maven repository suppport can be implemented in z2-base and does not require core changes. |
||
6 | |||
7 | 5 | Henning Blohm | h2. Principles |
8 | 1 | Henning Blohm | |
9 | 5 | Henning Blohm | 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. |
10 | |||
11 | h2. Name mapping and version resolution |
||
12 | |||
13 | 1 | Henning Blohm | Artefacts in Maven repos have a fully qualified name of the form |
14 | |||
15 | <pre> |
||
16 | <groupId>:<artifactId>:<version> |
||
17 | </pre> |
||
18 | |||
19 | 5 | Henning Blohm | or |
20 | 1 | Henning Blohm | |
21 | 5 | Henning Blohm | <pre> |
22 | <groupId>:<artifactId>:<packaging>:<version> |
||
23 | </pre> |
||
24 | 1 | Henning Blohm | |
25 | 5 | Henning Blohm | By default, a jar artifact @<groupId>:<artifactId>:<version>@ will result into a Java component of name |
26 | 1 | Henning Blohm | |
27 | <pre> |
||
28 | 5 | Henning Blohm | <groupId>:<artifactId>/java |
29 | 1 | Henning Blohm | </pre> |
30 | |||
31 | 5 | Henning Blohm | 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). |
32 | 1 | Henning Blohm | |
33 | 5 | Henning Blohm | h2. Example configuration |
34 | |||
35 | A maven repository component may look like this: |
||
36 | |||
37 | <pre> |
||
38 | com.zfabrik.systemStates.participation=com.zfabrik.boot.main/sysrepo_up |
||
39 | com.zfabrik.component.type=com.zfabrik.mvncr |
||
40 | 9 | Henning Blohm | mvncr.priority=200 |
41 | mvncr.roots=\ |
||
42 | org.springframework:spring-context:4.0.2.RELEASE,\ |
||
43 | 5 | Henning Blohm | org.springframework:spring-aspects:4.0.2.RELEASE,\ |
44 | org.springframework:spring-tx:4.0.2.RELEASE,\ |
||
45 | org.springframework:spring-orm:4.0.2.RELEASE,\ |
||
46 | org.springframework:spring-web:4.0.2.RELEASE,\ |
||
47 | org.springframework.security:spring-security-core:3.2.2.RELEASE,\ |
||
48 | org.springframework.security:spring-security-web:3.2.2.RELEASE,\ |
||
49 | org.springframework.security:spring-security-config:3.2.2.RELEASE,\ |
||
50 | org.springframework.security:spring-security-aspects:3.2.2.RELEASE,\ |
||
51 | 9 | Henning Blohm | org.hibernate:hibernate-entitymanager:4.3.4.Final,\ |
52 | 1 | Henning Blohm | aopalliance:aopalliance:1.0,\ |
53 | org.aspectj:aspectjweaver:1.7.4,\ |
||
54 | org.aspectj:aspectjtools:1.6.9,\ |
||
55 | 9 | Henning Blohm | |
56 | mvncr.excluded=\ |
||
57 | org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec |
||
58 | |||
59 | mvncr.managed=\ |
||
60 | commons-logging:commons-logging:1.1.2 |
||
61 | 5 | Henning Blohm | </pre> |
62 | |||
63 | 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. |
||
64 | |||
65 | The z2 core will use lazy component class loaders to make sure that use of include libraries has virtually no runtime penalty. |
||
66 | |||
67 | 13 | Henning Blohm | h2. Component properties |
68 | 6 | Henning Blohm | |
69 | 13 | Henning Blohm | |_. name |_. meaning |_. default | |
70 | | mvncr.settings | Specifies the location of the settings XML file relative to the components resources | settings.xml | |
||
71 | | mvncr.roots | A comman-separated list of root artifacts. See below for more details | n.a. | |
||
72 | | mvncr.priority | The repository priority in repository chaining as defined in IComponentsRepository | 500 | |
||
73 | | mvncr.managed | Fixed artifact versions, if encountered during recursive root resolution. This corresponds to a <dependencyManagement> section in a Maven POM file | n.a. | |
||
74 | | mvncr.excluded | A comma separated list of artifacts that will be skipped during resolution of any root | n.a. | |
||
75 | |||
76 | 5 | Henning Blohm | h2. Fine-Tuning of the Dependency Graph |
77 | 9 | Henning Blohm | |
78 | 5 | Henning Blohm | In order to deviate from the default resolution and mapping, maven repository roots may be specified with a query string like this: |
79 | 1 | Henning Blohm | |
80 | <pre> |
||
81 | 5 | Henning Blohm | org.springframework.security:spring-security-aspects:3.2.2.RELEASE?versioned=true&scope=RUNTIME&excluded=commons-logging:commons-logging:1.1.2 |
82 | 1 | Henning Blohm | </pre> |
83 | |||
84 | 13 | Henning Blohm | Admissable query params are |
85 | 1 | Henning Blohm | |
86 | 13 | Henning Blohm | |_. param |_. meaning | |
87 | | 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. | |
||
88 | | scope | Any of RUNTIME, COMPILE, PROVIDED, SYSTEM, TEST. Corresponds to the corresponding Maven dependency scopes. If set, non-optional dependencies of the respective scope will be traversed to resolve dependencies. | |
||
89 | | excluded | Exclusions on the dependency graph. | |
||
90 | 6 | Henning Blohm | |
91 | h2. Handling the impact of PROVIDED references |
||
92 | |||
93 | 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. |
||
94 | 8 | Henning Blohm | |
95 | 1 | Henning Blohm | 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: |
96 | |||
97 | <pre> |
||
98 | java.publicIncludes=\ |
||
99 | 6 | Henning Blohm | com.vaadin:vaadin-server?expand=true |
100 | 9 | Henning Blohm | </pre> |
101 | 12 | Henning Blohm | |
102 | 14 | Henning Blohm | h2. Modularising Maven Dependencies |
103 | |||
104 | At times, it is useful to not have all required dependency roots in one component declaration but rather allow some modularization-friendly spread out declaration of dependency roots within a system. |
||
105 | |||
106 | Note that having two sets of roots combined and resolved is not equivalent to having to independent Maven Component Repository declaration as version conflict resolution (to the higher version) will always happen within the scope of one Maven component repository. In fact, in most cases having one Maven Component Repository will be the only manageable approach. |
||
107 | |||
108 | In order to add a _fragment_ to a Maven Component Repository declare a component of type *com.zfabrik.mvncr.fragment* with the following properties |
||
109 | |||
110 | |_. name |_. meaning |_. default | |
||
111 | | mvncr.component | The component name of the MVNCR declaration this fragment adds to or a fragment adding to some other mvncr | |
||
112 | | mvncr.roots | As above. Will be merged with the repo this fragment adds to | n.a. | |
||
113 | | mvncr.managed | As above. Will be merged with the repo this fragment adds to | n.a. | |
||
114 | | mvncr.excluded | As above. Will be merged with the repo this fragment adds to | n.a. | |
||
115 | |||
116 | |||
117 | 12 | Henning Blohm | h2. Development Support |
118 | |||
119 | When running in Development mode, the repository will also provide the source (classifier) artifact if available, so that the Eclipsoid plugins will provide source code attachments to the development environment whenever possible during classpath resolution. |
||
120 | 9 | Henning Blohm | |
121 | h2. References |
||
122 | 10 | Henning Blohm | |
123 | 7 | Henning Blohm | * Main Javadoc: "MvnRepositoryResource":http://www.z2-environment.net/javadoc/com.zfabrik.mvncr!2Fjava/impl/com/zfabrik/impl/mvncr/MvnRepositoryResource.html |
124 | |||
125 | h2. To Dos |
||
126 | |||
127 | 1 | Henning Blohm | # Handling of SNAPSHOT-Versions to be revisited |