我希望拥有默认使用Java 8的代码,但需要修补它并生成兼容java7的jar。在这种情况下只是因为Optional
用法。有没有办法在构建生命周期中包含这样的工作流程?
答案 0 :(得分:0)
经过一些调查后,我会回复自己如何使用patch plugin和个人资料:
<properties>
<java.classifier>java8</java.classifier>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${java.classifier}</classifier>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>java7</id>
<properties>
<java.classifier>java7</java.classifier>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-patch-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<strip>1</strip>
<patches>
<patch>java7.patch</patch>
</patches>
</configuration>
<executions>
<execution>
<id>patch</id>
<phase>process-sources</phase>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</profile>
</profiles>
不是那么复杂......但可能有更好的解决方案。