maven中打不同JDK版本的jar包

最近项目中,I商机用jdk1.7,而ltc用jdk1.8,所以提供给他们的api都要不同的版本

  1. 修改pom.xml配置
 <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>${jar.source}</source>
          <target>${jar.target}</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>
 
  <properties>
    <!-- 这里省略属性 -->
  </properties>
  <profiles>
    <profile>
      <id>default</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <jar.source>1.8</jar.source>
        <jar.target>1.8</jar.target>
      </properties>
    </profile>
    <profile>
      <id>jdk17</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>jar</goal>
                </goals>
                <configuration>
                  <classifier>jdk17</classifier>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <jar.source>1.7</jar.source>
        <jar.target>1.7</jar.target>
      </properties>
    </profile>
  </profiles>
  1. 执行打包命令
mvn clean package -P jdk17
  1. 引入jar包时作以下修改
<dependency>
            <groupId>com.meicloud.meiqing</groupId>
            <artifactId>workflow-api</artifactId>
            <version>1.1.0-SNAPSHOT</version>
             <classifier>jdk17</classifier>  
        </dependency>

至此,jdk1.7的api打包成功

    原文作者:爱余星痕
    原文地址: https://www.jianshu.com/p/5f933b4ddd54
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞