0b255f6e60cfe6a8364aceb7526b6624579269cc
[docs.git] / docs / developer-guides / odl-parent-developer-guide.rst
1 .. _odl-parent-developer-guide:
2
3 ODL Parent Developer Guide
4 ==========================
5
6 Parent POMs
7 -----------
8
9 Overview
10 ~~~~~~~~
11
12 The ODL Parent component for OpenDaylight provides a number of Maven
13 parent POMs which allow Maven projects to be easily integrated in the
14 OpenDaylight ecosystem. Technically, the aim of projects in OpenDaylight
15 is to produce Karaf features, and these parent projects provide common
16 support for the different types of projects involved.
17
18 These parent projects are:
19
20 -  ``odlparent-lite`` — the basic parent POM for Maven modules which
21    don’t produce artifacts (*e.g.* aggregator POMs)
22
23 -  ``odlparent`` — the common parent POM for Maven modules containing
24    Java code
25
26 -  ``bundle-parent`` — the parent POM for Maven modules producing OSGi
27    bundles
28
29 The following parent projects are deprecated, but still used in Carbon:
30
31 -  ``feature-parent`` — the parent POM for Maven modules producing
32    Karaf 3 feature repositories
33
34 -  ``karaf-parent`` — the parent POM for Maven modules producing Karaf 3
35    distributions
36
37 The following parent projects are new in Carbon, for Karaf 4 support (which
38 won’t be complete until Nitrogen):
39
40 -  ``single-feature-parent`` — the parent POM for Maven modules producing
41    a single Karaf 4 feature
42
43 -  ``feature-repo-parent`` — the parent POM for Maven modules producing
44    Karaf 4 feature repositories
45
46 -  ``karaf4-parent`` — the parent POM for Maven modules producing Karaf 4
47    distributions
48
49 odlparent-lite
50 ~~~~~~~~~~~~~~
51
52 This is the base parent for all OpenDaylight Maven projects and
53 modules. It provides the following, notably to allow publishing
54 artifacts to Maven Central:
55
56 -  license information;
57
58 -  organization information;
59
60 -  issue management information (a link to our Bugzilla);
61
62 -  continuous integration information (a link to our Jenkins setup);
63
64 -  default Maven plugins (``maven-clean-plugin``,
65    ``maven-deploy-plugin``, ``maven-install-plugin``,
66    ``maven-javadoc-plugin`` with HelpMojo support,
67    ``maven-project-info-reports-plugin``, ``maven-site-plugin`` with
68    Asciidoc support, ``jdepend-maven-plugin``);
69
70 -  distribution management information.
71
72 It also defines two profiles which help during development:
73
74 -  ``q`` (``-Pq``), the quick profile, which disables tests, code
75    coverage, Javadoc generation, code analysis, etc. — anything which
76    isn’t necessary to build the bundles and features (see `this blog
77    post <http://blog2.vorburger.ch/2016/06/improve-maven-build-speed-with-q.html>`__
78    for details);
79
80 -  ``addInstallRepositoryPath``
81    (``-DaddInstallRepositoryPath=…/karaf/system``) which can be used to
82    drop a bundle in the appropriate Karaf location, to enable
83    hot-reloading of bundles during development (see `this blog
84    post <http://blog2.vorburger.ch/2016/06/maven-install-into-additional.html>`__
85    for details).
86
87 For modules which don’t produce any useful artifacts (*e.g.* aggregator
88 POMs), you should add the following to avoid processing artifacts:
89
90 ::
91
92     <build>
93         <plugins>
94             <plugin>
95                 <groupId>org.apache.maven.plugins</groupId>
96                 <artifactId>maven-deploy-plugin</artifactId>
97                 <configuration>
98                     <skip>true</skip>
99                 </configuration>
100             </plugin>
101             <plugin>
102                 <groupId>org.apache.maven.plugins</groupId>
103                 <artifactId>maven-install-plugin</artifactId>
104                 <configuration>
105                     <skip>true</skip>
106                 </configuration>
107             </plugin>
108         </plugins>
109     </build>
110
111 odlparent
112 ~~~~~~~~~
113
114 This inherits from ``odlparent-lite`` and mainly provides dependency and
115 plugin management for OpenDaylight projects.
116
117 If you use any of the following libraries, you should rely on
118 ``odlparent`` to provide the appropriate versions:
119
120 -  Akka (and Scala)
121
122 -  Apache Commons:
123
124    -  ``commons-codec``
125
126    -  ``commons-fileupload``
127
128    -  ``commons-io``
129
130    -  ``commons-lang``
131
132    -  ``commons-lang3``
133
134    -  ``commons-net``
135
136 -  Apache Shiro
137
138 -  Guava
139
140 -  JAX-RS with Jersey
141
142 -  JSON processing:
143
144    -  GSON
145
146    -  Jackson
147
148 -  Logging:
149
150    -  Logback
151
152    -  SLF4J
153
154 -  Netty
155
156 -  OSGi:
157
158    -  Apache Felix
159
160    -  core OSGi dependencies (``core``, ``compendium``\ …)
161
162 -  Testing:
163
164    -  Hamcrest
165
166    -  JSON assert
167
168    -  JUnit
169
170    -  Mockito
171
172    -  Pax Exam
173
174    -  PowerMock
175
176 -  XML/XSL:
177
178    -  Xerces
179
180    -  XML APIs
181
182 .. note::
183
184     This list isn’t exhaustive. It’s also not cast in stone; if you’d
185     like to add a new dependency (or migrate a dependency), please
186     contact `the mailing
187     list <https://lists.opendaylight.org/g/kernel-dev>`__.
188
189 ``odlparent`` also enforces some Checkstyle verification rules. In
190 particular, it enforces the common license header used in all
191 OpenDaylight code:
192
193 ::
194
195     /*
196      * Copyright © ${year} ${holder} and others.  All rights reserved.
197      *
198      * This program and the accompanying materials are made available under the
199      * terms of the Eclipse Public License v1.0 which accompanies this distribution,
200      * and is available at http://www.eclipse.org/legal/epl-v10.html
201      */
202
203 where “\ ``${year}``\ ” is initially the first year of publication, then
204 (after a year has passed) the first and latest years of publication,
205 separated by commas (*e.g.* “2014, 2016”), and “\ ``${holder}``\ ” is
206 the initial copyright holder (typically, the first author’s employer).
207 “All rights reserved” is optional.
208
209 If you need to disable this license check, *e.g.* for files imported
210 under another license (EPL-compatible of course), you can override the
211 ``maven-checkstyle-plugin`` configuration. ``features-test`` does this
212 for its ``CustomBundleUrlStreamHandlerFactory`` class, which is
213 ASL-licensed:
214
215 ::
216
217     <plugin>
218         <artifactId>maven-checkstyle-plugin</artifactId>
219         <executions>
220             <execution>
221                 <id>check-license</id>
222                 <goals>
223                     <goal>check</goal>
224                 </goals>
225                 <phase>process-sources</phase>
226                 <configuration>
227                     <configLocation>check-license.xml</configLocation>
228                     <headerLocation>EPL-LICENSE.regexp.txt</headerLocation>
229                     <includeResources>false</includeResources>
230                     <includeTestResources>false</includeTestResources>
231                     <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
232                     <excludes>
233                         <!-- Skip Apache Licensed files -->
234                         org/opendaylight/odlparent/featuretest/CustomBundleUrlStreamHandlerFactory.java
235                     </excludes>
236                     <failsOnError>false</failsOnError>
237                     <consoleOutput>true</consoleOutput>
238                 </configuration>
239             </execution>
240         </executions>
241     </plugin>
242
243 bundle-parent
244 ~~~~~~~~~~~~~
245
246 This inherits from ``odlparent`` and enables functionality useful for
247 OSGi bundles:
248
249 -  ``maven-javadoc-plugin`` is activated, to build the Javadoc JAR;
250
251 -  ``maven-source-plugin`` is activated, to build the source JAR;
252
253 -  ``maven-bundle-plugin`` is activated (including extensions), to build
254    OSGi bundles (using the “bundle” packaging).
255
256 In addition to this, JUnit is included as a default dependency in “test”
257 scope.
258
259 features-parent
260 ~~~~~~~~~~~~~~~
261
262 This inherits from ``odlparent`` and enables functionality useful for
263 Karaf features:
264
265 -  ``karaf-maven-plugin`` is activated, to build Karaf features — but
266    for OpenDaylight, projects need to use “jar” packaging (**not**
267    “feature” or “kar”);
268
269 -  ``features.xml`` files are processed from templates stored in
270    ``src/main/features/features.xml``;
271
272 -  Karaf features are tested after build to ensure they can be activated
273    in a Karaf container.
274
275 The ``features.xml`` processing allows versions to be ommitted from
276 certain feature dependencies, and replaced with “\ ``{{version}}``\ ”.
277 For example:
278
279 ::
280
281     <features name="odl-mdsal-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
282        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
283        xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
284
285         <repository>mvn:org.opendaylight.odlparent/features-odlparent/{{VERSION}}/xml/features</repository>
286
287         [...]
288         <feature name='odl-mdsal-broker-local' version='${project.version}' description="OpenDaylight :: MDSAL :: Broker">
289             <feature version='${yangtools.version}'>odl-yangtools-common</feature>
290             <feature version='${mdsal.version}'>odl-mdsal-binding-dom-adapter</feature>
291             <feature version='${mdsal.model.version}'>odl-mdsal-models</feature>
292             <feature version='${project.version}'>odl-mdsal-common</feature>
293             <feature version='${config.version}'>odl-config-startup</feature>
294             <feature version='${config.version}'>odl-config-netty</feature>
295             <feature version='[3.3.0,4.0.0)'>odl-lmax</feature>
296             [...]
297             <bundle>mvn:org.opendaylight.controller/sal-dom-broker-config/{{VERSION}}</bundle>
298             <bundle start-level="40">mvn:org.opendaylight.controller/blueprint/{{VERSION}}</bundle>
299             <configfile finalname="${config.configfile.directory}/${config.mdsal.configfile}">mvn:org.opendaylight.controller/md-sal-config/{{VERSION}}/xml/config</configfile>
300         </feature>
301
302 As illustrated, versions can be ommitted in this way for repository
303 dependencies, bundle dependencies and configuration files. They must be
304 specified traditionally (either hard-coded, or using Maven properties)
305 for feature dependencies.
306
307 karaf-parent
308 ~~~~~~~~~~~~
309
310 This allows building a Karaf 3 distribution, typically for local testing
311 purposes. Any runtime-scoped feature dependencies will be included in the
312 distribution, and the ``karaf.localFeature`` property can be used to
313 specify the boot feature (in addition to ``standard``).
314
315 single-feature-parent
316 ~~~~~~~~~~~~~~~~~~~~~
317
318 This inherits from ``odlparent`` and enables functionality useful for
319 Karaf 4 features:
320
321 -  ``karaf-maven-plugin`` is activated, to build Karaf features, typically
322    with “feature” packaging (“kar” is also supported);
323
324 -  ``feature.xml`` files are generated based on the compile-scope dependencies
325    defined in the POM, optionally initialised from a stub in
326    ``src/main/feature/feature.xml``.
327
328 -  Karaf features are tested after build to ensure they can be activated
329    in a Karaf container.
330
331 The ``feature.xml`` processing adds transitive dependencies by default, which
332 allows features to be defined using only the most significant dependencies
333 (those that define the feature); other requirements are determined
334 automatically as long as they exist as Maven dependencies.
335
336 “configfiles” need to be defined both as Maven dependencies (with the
337 appropriate type and classifier) and as ``<configfile>`` elements in the
338 ``feature.xml`` stub.
339
340 Other features which a feature depends on need to be defined as Maven
341 dependencies with type “xml” and classifier “features” (note the plural here).
342
343 feature-repo-parent
344 ~~~~~~~~~~~~~~~~~~~
345
346 This inherits from ``odlparent`` and enables functionality useful for
347 Karaf 4 feature repositories. It follows the same principles as
348 ``single-feature-parent``, but is designed specifically for repositories
349 and should be used only for this type of artifacts.
350
351 It builds a feature repository referencing all the (feature) dependencies
352 listed in the POM.
353
354 karaf4-parent
355 ~~~~~~~~~~~~~
356
357 This allows building a Karaf 4 distribution, typically for local testing
358 purposes. Any runtime-scoped feature dependencies will be included in the
359 distribution, and the ``karaf.localFeature`` property can be used to
360 specify the boot feature (in addition to ``standard``).
361
362 Features (for Karaf 3)
363 ----------------------
364
365 The ODL Parent component for OpenDaylight provides a number of Karaf 3
366 features which can be used by other Karaf 3 features to use certain
367 third-party upstream dependencies.
368
369 These features are:
370
371 -  Akka features (in the ``features-akka`` repository):
372
373    -  ``odl-akka-all`` — all Akka bundles;
374
375    -  ``odl-akka-scala-2.11`` — Scala runtime for OpenDaylight;
376
377    -  ``odl-akka-system-2.4`` — Akka actor framework bundles;
378
379    -  ``odl-akka-clustering-2.4`` — Akka clustering bundles and
380       dependencies;
381
382    -  ``odl-akka-leveldb-0.7`` — LevelDB;
383
384    -  ``odl-akka-persistence-2.4`` — Akka persistence;
385
386 -  general third-party features (in the ``features-odlparent``
387    repository):
388
389    -  ``odl-netty-4`` — all Netty bundles;
390
391    -  ``odl-guava-18`` — Guava 18;
392
393    -  ``odl-guava-21`` — Guava 21 (not indended for use in Carbon);
394
395    -  ``odl-lmax-3`` — LMAX Disruptor;
396
397    -  ``odl-triemap-0.2`` — Concurrent Trie HashMap.
398
399 To use these, you need to declare a dependency on the appropriate
400 repository in your ``features.xml`` file:
401
402 ::
403
404     <repository>mvn:org.opendaylight.odlparent/features-odlparent/{{VERSION}}/xml/features</repository>
405
406 and then include the feature, *e.g.*:
407
408 ::
409
410     <feature name='odl-mdsal-broker-local' version='${project.version}' description="OpenDaylight :: MDSAL :: Broker">
411         [...]
412         <feature version='[3.3.0,4.0.0)'>odl-lmax</feature>
413         [...]
414     </feature>
415
416 You also need to depend on the features repository in your POM:
417
418 ::
419
420     <dependency>
421         <groupId>org.opendaylight.odlparent</groupId>
422         <artifactId>features-odlparent</artifactId>
423         <classifier>features</classifier>
424         <type>xml</type>
425     </dependency>
426
427 assuming the appropriate dependency management:
428
429 ::
430
431     <dependencyManagement>
432         <dependencies>
433             <dependency>
434                 <groupId>org.opendaylight.odlparent</groupId>
435                 <artifactId>odlparent-artifacts</artifactId>
436                 <version>1.8.0-SNAPSHOT</version>
437                 <scope>import</scope>
438                 <type>pom</type>
439             </dependency>
440         </dependencies>
441     </dependencyManagement>
442
443 (the version number there is appropriate for Carbon). For the time being
444 you also need to depend separately on the individual JARs as
445 compile-time dependencies to build your dependent code; the relevant
446 dependencies are managed in ``odlparent``'s dependency management.
447
448 | The suggested version ranges are as follows:
449
450 -  ``odl-netty``: ``[4.0.37,4.1.0)`` or ``[4.0.37,5.0.0)``;
451
452 -  ``odl-guava``: ``[18,19)`` (if your code is ready for it, ``[19,20)``
453    is also available, but the current default version of Guava in
454    OpenDaylight is 18);
455
456 -  ``odl-lmax``: ``[3.3.4,4.0.0)``
457
458 Features (for Karaf 4)
459 ----------------------
460
461 There are equivalent features to all the Karaf 3 features, for Karaf 4.
462 The repositories use “features4” instead of “features”, and the features
463 use “odl4” instead of “odl”.
464
465 The following new features are specific to Karaf 4:
466
467 -  Karaf wrapper features (also in the ``features4-odlparent``
468    repository) — these can be used to pull in a Karaf feature
469    using a Maven dependency in a POM:
470
471    -  ``odl-karaf-feat-feature`` — the Karaf ``feature`` feature;
472
473    -  ``odl-karaf-feat-jdbc`` — the Karaf ``jdbc`` feature;
474
475    -  ``odl-karaf-feat-jetty`` — the Karaf ``jetty`` feature;
476
477    -  ``odl-karaf-feat-war`` — the Karaf ``war`` feature.
478
479 To use these, all you need to do now is add the appropriate dependency
480 in your feature POM; for example:
481
482 ::
483
484     <dependency>
485         <groupId>org.opendaylight.odlparent</groupId>
486         <artifactId>odl4-guava-18</artifactId>
487         <classifier>features</classifier>
488         <type>xml</type>
489     </dependency>
490
491 assuming the appropriate dependency management:
492
493 ::
494
495     <dependencyManagement>
496         <dependencies>
497             <dependency>
498                 <groupId>org.opendaylight.odlparent</groupId>
499                 <artifactId>odlparent-artifacts</artifactId>
500                 <version>1.8.0-SNAPSHOT</version>
501                 <scope>import</scope>
502                 <type>pom</type>
503             </dependency>
504         </dependencies>
505     </dependencyManagement>
506
507 (the version number there is appropriate for Carbon). We no longer use version
508 ranges, the feature dependencies all use the ``odlparent`` version (but you
509 should rely on the artifacts POM).