mojohaus / flatten-maven-plugin

Flatten Maven Plugin
https://www.mojohaus.org/flatten-maven-plugin/
Apache License 2.0
203 stars 85 forks source link

How to keep properties like "${java.home}" ? #72

Closed hengyunabc closed 6 years ago

hengyunabc commented 6 years ago

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:

  <dependencies>
    <dependency>
      <groupId>com.oracle.java</groupId>
      <artifactId>tools</artifactId>
      <version>8.0</version>
      <scope>system</scope>
      <systemPath>/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre/../lib/tools.jar</systemPath>
    </dependency>
  </dependencies>

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} ?

khmarbaise commented 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...

hengyunabc commented 6 years ago

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>
hengyunabc commented 6 years ago

I found a solution.

        <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>