日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Example of how to use both JDK 7 and JDK 8 in one build.--reference

發布時間:2025/4/5 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Example of how to use both JDK 7 and JDK 8 in one build.--reference 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

JDK 8 Released

Most of us won’t be able to use/deploy JDK 8 in production for a looong time. But that shouldn’t stop us from using it, right?

It should be possible to sneak in JDK 8 in the back way, the same way we snuck in Groovy and other libraries we wanted to use.

The Test Suite to the rescue

The Maven compiler plugin run in two separate lifecycles, compile and testCompile. Those can be configured separately.

The Maven Compiler even comes with support out of the box to separate them.

If you’re lucky and don’t have some elaborate parent pom setup that sets up most of the plugins for you, the only thing you need to do is add the following to your pom:

<properties><maven.compiler.target>1.7</maven.compiler.target><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.testTarget>1.8</maven.compiler.testTarget><maven.compiler.testSource>1.8</maven.compiler.testSource></properties>

Now your src/main/java is compiled with target 1.7, and src/main/test compiled with target 1.8.

If you happen to have a parent pom that dominates your world, you might have to override the configuration a bit deeper. Something similar to this should work:

<build><plugins> ...<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><executions><execution><id>default-compile</id><configuration><showDeprecation>true</showDeprecation><showWarnings>true</showWarnings><compilerArguments><source>${maven.compiler.target}</source><target>${maven.compiler.source}</target></compilerArguments></configuration></execution><execution><id>default-testCompile</id><configuration><showDeprecation>true</showDeprecation><showWarnings>true</showWarnings><compilerArguments><source>${maven.compiler.testTarget}</source><target>${maven.compiler.testSource}</target></compilerArguments></configuration></execution></executions></plugin> ...</plugins></build>

To be able to test your project you’re now forced to use JDK 8. We probably want to tell the other developers that by enforcing the same level as our tests.

Under the build section add:

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-enforcer-plugin</artifactId><version>1.3.1</version><executions><execution><id>enforce-java</id><goals><goal>enforce</goal></goals><configuration><rules><requireJavaVersion><version>${maven.compiler.testTarget}</version></requireJavaVersion></rules></configuration></execution></executions></plugin>

With that mind, even tho we compile with target 1.7, the compiler doesn’t know the difference between the API’s available in 1.7 and 1.8. Which means it will still compile just fine if your src/main/java classes contain calls to APIs new in 1.8. We would want to avoid JDK 8 sneaking into production, so we need to setup a API verifier that fail the build if non 1.7 API’s are found by adding this to our build section:

<plugin><groupId>org.codehaus.mojo</groupId><artifactId>animal-sniffer-maven-plugin</artifactId><version>1.7</version><executions><execution><id>signature-check</id><phase>verify</phase><goals><goal>check</goal></goals></execution></executions><configuration><signature><groupId>org.codehaus.mojo.signature</groupId><artifactId>java17</artifactId><version>1.0</version></signature></configuration></plugin>

With the project setup, we can now enjoy JDK 8 in our test suite.

Our boring JDK 1.7 source:

import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable;public class DoSomething {public String execute(Callable<String> call) throws Exception {return call.call();}public List<String> list() {return Arrays.asList("a", "b", "c", "d");} }

And the cool new JDK 8 enabled Test Suite:

import java.util.Optional;import org.junit.Assert; import org.junit.Test;public class DoSomethingTestClase {public static final String TEST = "ABCD";@Testpublic void shouldReturnString() throws Exception {String result = new DoSomething().execute(()-> TEST);Assert.assertEquals(TEST, result);}@Testpublic void shouldFilterResult() throws Exception {Optional<String> result = new DoSomething().list().stream().map((a)-> a.toUpperCase()).reduce((a, b)->a+b);Assert.assertTrue(result.isPresent());Assert.assertEquals(TEST, result.get());} }

Enjoy!

reference from:https://gist.github.com/aslakknutsen/9648594

轉載于:https://www.cnblogs.com/davidwang456/p/3999513.html

總結

以上是生活随笔為你收集整理的Example of how to use both JDK 7 and JDK 8 in one build.--reference的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 四虎一区二区三区 | 亚洲精品乱码久久 | 国产精品久久久久久久久夜色 | 女色婷婷 | 亚洲一区二区三区四区电影 | 国产一级一级国产 | 成年人看的免费视频 | 久久国内偷拍 | 黄色激情在线 | 亚洲欧美另类国产 | 欧美激情视频一区二区三区在线播放 | 特级毛片在线观看 | 天天操天天看 | 在线观看中文字幕第一页 | 国产亚洲精品久久久久四川人 | 日韩在线一卡二卡 | 在线看污片| 日韩成人免费在线观看 | 亚洲成人一 | 99国内精品| 在线91观看 | caoprom97| 毛片一级在线观看 | 日韩二区三区 | 男女日批 | 日韩av毛片 | 精品国产中文字幕 | 亚洲伊人久久综合 | 国产精品99久久久久久久久久久久 | 久久综合婷婷 | 日本少妇色视频 | aaa亚洲 | 久久久久免费精品视频 | 欧美日韩福利视频 | 精品久久伊人 | 亚洲精选中文字幕 | 午夜视频一区二区 | 99热精品在线播放 | 成人性免费视频 | 在线a网站 | 亚洲国产精品免费视频 | 浪漫樱花动漫在线观看免费 | 国产在线观看免费视频软件 | 日韩一二三级 | 96视频在线| 国产精品久草 | 国产三级精品三级 | 欲色网站 | 人妻一区二区视频 | 国产福利资源 | 国产成人av一区二区三区 | 黄色在线视频播放 | 欧美日韩亚洲一区 | 99久久精品免费看国产四区 | 少妇高潮网站 | 成人免费一区二区三区 | 992av| www色网| 欧美一区二区三区成人片在线 | 中文字幕免费高 | 欧美freesex黑人又粗又大 | 明星毛片 | 亚洲不卡影院 | 国产特黄 | 中文字幕女同女同女同 | 欧美一级淫片007 | 九九影院最新理论片 | 国产成人精品一区二区三 | 国产一区二区日韩 | 91麻豆国产福利精品 | 国产91在线高潮白浆在线观看 | 最近免费中文字幕大全免费版视频 | 重囗味sm一区二区三区 | 1024金沙人妻一区二区三区 | 欧美在线视频二区 | 夜夜操操 | 天天天天干 | 91午夜免费视频 | 亚洲色图15p | 99久久综合国产精品二区 | 18视频在线观看网站 | 国产亚洲成人av | 成人免费黄色大片 | 国产尤物视频在线观看 | 久久丫精品 | 青青草91久久久久久久久 | 亚洲激情网站 | 一级片自拍 | 最新国产一区 | 亚洲av午夜精品一区二区三区 | 国产传媒中文字幕 | 亚洲精品中文字幕成人片 | 青青操视频在线 | 一二三区在线视频 | 91成品人影院 | 亚洲国产欧美在线观看 | 欧美日韩精品在线播放 | 精品一区二区欧美 | 顶级黄色片|