我对maven不太熟悉,在尝试使用多模块项目时,我开始想知道如何为父maven pom中的所有子模块指定java版本.直到今天我才使用:
<properties>
<java.version>1.8</java.version>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是在研究时我发现你也可以在maven编译器插件中指定java版本,就像那样:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
然后将其包装到插件管理标签中以启用子poms的使用.所以第一个问题是在属性和maven编译器插件中设置java版本有什么区别?
我找不到明确的答案,但在研究过程中我发现你也可以用这种方式指定java版本:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
这表明编译器插件就在那里,即使我没有明确声明它.运行mvn包输出
maven-compiler-plugin:3.1:compile (default-compile) @ testproj ---
Run Code Online (Sandbox Code Playgroud)
和其他一些我没有声明的插件.那些插件默认是隐藏的maven pom的一部分吗?在属性和maven插件配置元素中设置源/目标是否有任何差异?
还有一些其他问题 - 应该采用哪种方式(以及何时不相等)?哪一个最适合多模块项目,如果在pom中指定的java版本与JAVA_HOME中指向的版本不同,会发生什么?
我需要很快将应用程序升级到Java 11,我想知道与Java 11兼容的最小Spring版本是什么.
我目前正在使用Java 8和Spring 4.2.7.
我是Maven的新手.当我尝试引用任何maven插件文档时,我总是看到参数定义的以下格式:名称说明{参数名称} {description}默认值为:... 用户属性为:...
在大多数情况下,我看到user属性与参数名称相同.我想知道"用户属性"和"参数名称"之间的区别.我认为参数名称在配置它们时指定对应插件的参数值时应该是元素标签名称,但是"用户属性"的用法是什么?
我刚刚迁移到JDK 11以使用最新的Java LTS版本.如果我将Eclipse中的执行JRE从10更改为11(并且只有那时),当我尝试运行我的测试时,我得到以下异常堆栈跟踪(我删除了一些部分以方便阅读).
请注意,如果我切换回jdk-10,一切都按预期工作.显然我使用Spring启动和Hibernate作为我的ORM.我已经在http://in.relation.to/2018/09/13/using-hibernate-orm-with-jdk11/中检查了该文章,并尝试解决这些依赖性问题.我的pom.xml也在这里显示.
Spring Boot和/或Hibernate与jdk-11之间是否存在已知的不兼容性?也许pom.xml中缺少另一个引用?
编辑:正如@nullpointer正确指出的那样,Spring 5.1支持java 11.但是,我的问题显然是指Spring Boot.
pom.xml中:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.5.4</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal> …Run Code Online (Sandbox Code Playgroud) 我正在将 Maven 构建的 Java 8 应用程序升级到 Java 11。在我的 POM 中,我指定:
<properties>
<java.version>1.11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
当我使用正常的 Maven 构建调用来构建我的应用程序时:
mvn verify -Plocal -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Run Code Online (Sandbox Code Playgroud)
我得到:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< example.com:myapp-svc >------------------------
[INFO] Building myapp-svc 1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-checkstyle-plugin:3.1.2:check (validate) @ myapp-svc ---
[WARNING] Old version of checkstyle detected. Consider updating to >= v8.30
[WARNING] For more information see: https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
[INFO] Starting audit...
Audit done.
[INFO] You have 0 Checkstyle violations.
[INFO]
[INFO] --- …Run Code Online (Sandbox Code Playgroud) java ×4
java-11 ×3
maven ×3
hibernate ×1
java-8 ×1
maven-3 ×1
maven-plugin ×1
spring ×1
spring-boot ×1