Fraction detection mode
Swarm Maven plugin can work in different fraction detection modes. If you do not provide fraction dependencies manually, it runs in the when-missing mode. We have already seen the behavior of this mode in our previous examples: when no direct fraction dependency is provided, the plugin performs auto-detection. On the other hand, if we provide at least one fraction dependency manually, the auto-detection mode is turned off. This is the reason why our last example wasn't built with the CDI fraction included: adding the JAX-RS fraction manually turned auto-detection off.
Is there something we can do about it? Yup, we can use a different detection mode: force. This mode makes auto-detection work every time. After detecting the fractions that are used, it merges the detection result with fractions configured by the user.
Let's reconfigure our example to make it work:
(...)
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- 1 -->
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs</artifactId>
<version>${version.wildfly.swarm}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<!-- 2 -->
<configuration>
<fractionDetectMode>force</fractionDetectMode>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Again, only the JAX-RS fraction is configured (1); however, because we have configured the Maven plugin with the force detection mode (2), Swarm will also detect the previously missing CDI fraction. If we run our application again, we will see that all necessary fractions were detected and the application works correctly.
We have seen two fraction detection modes: when-missing and force. Is there another? Yes, there is one more: never. In this mode, as its name implies, the fractions are never detected, and you always have to provide all of them manually.