Skip to main content

Updating Libraries in expansion

It is possible to change the versions of libraries in the expanded projects by redefining Library instances in a DataResource file.

pom.xml

To achieve this, we need to create a new expansion-resource.

In the pom.xml, we need to attach the expansionResource goal of the expanders-maven-plugin to the build. In addition, we can define dependencies for the libraries we want to update.

EXPANDERS VERSION

In this example we also define dependencies on prime-core and Expanders. To avoid introducing unexpected versions in your expansion, it is best to keep these versions in sync with the prime-core and expanders version used in your project.

pom.xml
<?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>org.normalizedsystems.example</groupId>
<artifactId>library-updates</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<expanders-maven-plugin.version>2024.7.0</expanders-maven-plugin.version>
<struts2.version>6.3.0.1</struts2.version>
</properties>
<dependencies>
<!-- prime-core and Expanders versions are best aligned with expansion-resource stack -->
<dependency>
<groupId>net.democritus.metamodel</groupId>
<artifactId>prime-core</artifactId>
<version>2024.8.2</version>
</dependency>
<!-- Dependency on Expanders makes sure this expansion-resource in loaded after Expanders -->
<dependency>
<groupId>net.democritus</groupId>
<artifactId>Expanders</artifactId>
<version>7.8.2</version>
</dependency>
<!-- By adding the dependency to the pom.xml file, the versions can be managed with maven. -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<!-- Filter xml files to insert versions from the properties in the pom.xml file. -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>net.democritus.maven.plugins</groupId>
<artifactId>expanders-maven-plugin</artifactId>
<version>${expanders-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>expansionResource</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

libraries.xml

Next, we define a libraries.xml data-resource. In this file, the name of the library matches Library instances already defined by Expanders. The modelLoader will merge the data by applying the new versions of the Library instances.

src/main/resources/data/libraries.xml
<dataResource type="elements::Library">
<library name="struts2-core">
<version>${struts2.version}</version>
</library>
<library name="struts2-json-plugin">
<version>${struts2.version}</version>
</library>
</dataResource>
DOWNGRADING VERSIONS

Note that it is possible to use this mechanism to downgrade the versions of libraries. There is no system in place to keep this from happening. It is the responsibility of the developer creating this expansion-resource to keep the version up-to-date. This way, you keep up-to-date with the latest security patches and avoid api conflicts with the expanded code.