I am trying to build multi-release jar for a maven project involving external dependencies. The reason why I emphasize on "external dependencies" is because I succeeded in building multi-release jar following the instructions here: http://in.relation.to/2017/02/13/building-multi-release-jars-with-maven/ for a project which no external dependencies in the pom. When I altered this project to have a dependency in the pom, I got error saying: package does not exist. The reported package exists in the dependency included. This is the project structure:
Pom.xml:
<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.hibernate.demos</groupId>
<artifactId>multi-release-jar-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>multi-release-jar-demo</name>
<url>http://hibernate.org/</url>
<properties>
<commonslang.version>3.8.1</commonslang.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java9.sourceDirectory>${project.basedir}/src/main/java9</java9.sourceDirectory>
<java9.build.outputDirectory>${project.build.directory}/classes-java9</java9.build.outputDirectory>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>compile-java9</id>
<phase>compile</phase>
<configuration>
<tasks>
<mkdir dir="${java9.build.outputDirectory}" />
<javac srcdir="${java9.sourceDirectory}" destdir="${java9.build.outputDirectory}"
classpath="${project.build.outputDirectory}" includeantruntime="false" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
<resources>
<resource>
<directory>${java9.build.outputDirectory}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<!--<Main-Class>org.hibernate.demos.mrjar.Main</Main-Class>-->
</manifestEntries>
</archive>
<!--<finalName>mr-jar-demo</finalName>-->
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>initialize</id>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
src/main/java9/org/hibernate/demos/mrjar/ProcessIdProvider.java:
public class ProcessIdProvider {
public ProcessIdDescriptor getPid() {
Configuration properties = null;
long pid = ProcessHandle.current().pid();
return new ProcessIdDescriptor( pid, "ProcessHandle" );
}
}
Error:
Documents/Development/hibernate-demos/java9/multi-release-jar-demo/src/main/java9/org/hibernate/demos/mrjar/ProcessIdProvider.java:7: error: package org.apache.commons.configuration does not exist
import org.apache.commons.configuration.Configuration;
^
/Documents/Development/hibernate-demos/java9/multi-release-jar-demo/src/main/java9/org/hibernate/demos/mrjar/ProcessIdProvider.java:17: error: cannot find symbol
Configuration properties = null;
^
symbol: class Configuration
location: class ProcessIdProvider
To note, this error appears only for the class residing inside the folder src/main/java9 and the file inside src/main/java compiles successfully. I don't seem to find any sample maven project with dependencies building a multi-release jar.