admin管理员组文章数量:1374895
On my computer, I have Java 11. I have a Java project that uses Maven. I have two GIT branches, to generate a jar in version 11 and another in version 1.8.
On my branch, which is planned for 1.8, in the maven-compiler-plugin
plugin, I have correctly specified the source and target as 1.8. Unfortunately, after cherry-picking my Java 11 branch from the Java 1.8 branch, I'm using a method that is only available for Java 11 (I use java.lang.String#stripTrailing
, available since Java 11+). The compilation doesn't give me a NoSuchMethodError
. Furthermore, when tests are run via the default Maven tasks, I don't get any errors, even though that should be the case. How can I make the error reappear without having to install two Java versions and change the Java runtime when I switch branches?
c:\temp>mvn -v
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: C:\Java\apache-maven-3.9.8
Java version: 11.0.16, vendor: Oracle Corporation, runtime: c:\Java\jdk-11.0.16
On my computer, I have Java 11. I have a Java project that uses Maven. I have two GIT branches, to generate a jar in version 11 and another in version 1.8.
On my branch, which is planned for 1.8, in the maven-compiler-plugin
plugin, I have correctly specified the source and target as 1.8. Unfortunately, after cherry-picking my Java 11 branch from the Java 1.8 branch, I'm using a method that is only available for Java 11 (I use java.lang.String#stripTrailing
, available since Java 11+). The compilation doesn't give me a NoSuchMethodError
. Furthermore, when tests are run via the default Maven tasks, I don't get any errors, even though that should be the case. How can I make the error reappear without having to install two Java versions and change the Java runtime when I switch branches?
c:\temp>mvn -v
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: C:\Java\apache-maven-3.9.8
Java version: 11.0.16, vendor: Oracle Corporation, runtime: c:\Java\jdk-11.0.16
Share
Improve this question
edited Apr 1 at 8:13
jonrsharpe
122k30 gold badges268 silver badges475 bronze badges
asked Apr 1 at 8:11
AnswerrerAnswerrer
3,5934 gold badges11 silver badges19 bronze badges
3
- stackoverflow/a/19324816/984823 So indeed the real java 8 is used. And make a unit test that maven runs with java 8. – Joop Eggen Commented Apr 1 at 8:26
- This solution requires all contributors to have this specific configuration. Therefore, the configuration is not linked to the project and must be replicated on developer workstations and in CI pipelines. Is it not possible to have a working configuration in the GIT project ? – Answerrer Commented Apr 1 at 8:35
- 1 Something with a settings.xml you mean, stackoverflow/a/20787334/984823 – Joop Eggen Commented Apr 1 at 8:45
1 Answer
Reset to default 3You need to set
<properties>
<mavenpiler.release>8</mavenpiler.release>
</properties>
as well so that you only compile to the Java 8 API.
本文标签: mavenMethods not available for compiletime Java versionStack Overflow
版权声明:本文标题:maven - Methods not available for compile-time Java version - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743900832a2558644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论