Closed hengyunabc closed 6 years ago
Very short hint. If you have a system scope dependency this should never end up in a resulting pom file cause it is always wrong and only works on your system nowhere else..System Scope is deprecated for a long time...and should not be used...furthermore with JDK9+ this will not work anymore either...
Thanks, I know that systemPath is deprecated, but I need to use com.sun.tools.attach.VirtualMachine
api, so I need tools.jar dependency.
In JDK9+ , I can use profile:
<activation>
<jdk>[1.6,1.8]</jdk>
</activation>
I found a solution.
Move the code use com.sun.tools.attach.VirtualMachine
api into a separate module.
The separate module scope is provided
<dependency>
<groupId>aaa</groupId>
<artifactId>bbb</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>include-class</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>aaa</groupId>
<artifactId>bbb</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includes>**/*.class</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>src-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/unpack-sources</outputDirectory>
<includeArtifactIds>bbb</includeArtifactIds>
<includes>**/*.java</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>prepare-package</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/unpack-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I found a test case under it:
https://github.com/mojohaus/flatten-maven-plugin/blob/master/src/it/projects/system-scope-dep-variable/pom.xml
Run
mvn clean package
, Result:I found some infornation from : https://github.com/mojohaus/flatten-maven-plugin/issues/12#issuecomment-160236080 , is there any plan to support exclusion for resolving ${java.home} and ${java.version} ?