Runtime Dependencies
Some Expanders will require runtime libraries to be added to the expanded project. These libraries can be defined declaratively.
To do so, we need to define:
- a list of libraries
- a LayerImplementation that attaches the libraries to a LayerType.
For a guide on how to use LayerImplementations in expanders, see this article.
Library
A library has a unique name, a groupId, artifactId and version.
<dataResource type="elements::Library">
<library name="solr-solrj">
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>9.2.1</version>
<technology name="APACHE SOLR"/>
<type>runtime</type>
</library>
</dataResource>
Type can be declared as one of the 3 following types:
- runtime: needed during runtime
- compilation: only needed during compilation (will not be included in the
.ear
file) - test: only needed during test
If you have a LayerImplementation, you can attach a Library:
<dataResource type="elements::LayerImplementation">
<layerImplementation name="Solr Search">
<technology name="APACHE SOLR"/>
<condition>component.getOption('solr.includeSearch').defined</condition>
<layerDependencys>
<layerDependency>
<library name="solr-solrj"/>
</layerDependency>
</layerDependencys>
</layerImplementation>
</dataResource>
A dependency will be added to the pom.xml
file of that layer.
Filtered Resources
It can be useful to insert versions into the libraries.xml
file using maven filtering.
- In your
pom.xml
, define 2 resources in<build>
:
<project>
...
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
...
</project>
- Move your
libraries.xml
file to resources-filtered. - Replace the version of the library with a placeholder:
<dataResource type="elements::Library">
<library name="solr-solrj">
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
<technology name="APACHE SOLR"/>
<type>runtime</type>
</library>
</dataResource>
- Define a property in your
pom.xml
defining the version:
<properties>
<solr.version>9.2.1</solr.version>
</properties>