We mixed two of the answers found here to solve a similar problem. Our project needs a JAR only in compile stage, but add a local dependency, using system scope, it is unuseful because Maven refuse the artifact publication with an error related to a missing dependency.
The snippets used are the following:
<properties> <classpathfile>${basedir}/classpathfile.classpath</classpathfile> </properties>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>build-classpath</id> <phase>generate-sources</phase> <goals> <goal>build-classpath</goal> </goals> <configuration> <outputFile>${classpathfile}</outputFile> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>generate-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <source> def file = new File(project.properties.classpathfile) project.properties.originalClassPath = file.getText() </source> </configuration> </execution> </executions> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <compilerArgs> <arg>-cp</arg> <arg>${originalClassPath}${path.separator}${basedir}/../../../bin/POM_RUNTIME_PLACEHOLDER/ExtraJar.jar</arg> </compilerArgs> </configuration> </plugin>
Maven is able to compile and successfully deploy the artifacts. If anyone is interested the full POM is available in GitHub under project NuReflector, defaultPOM.template under src/NuReflector.