我正在将旧库迁移到 java 8(以及 11 和 17 之后),并且收到一条错误消息,提示我在我们的构建服务器上使用的是 java 1.4(本地构建工作正常):
17:53:21 [INFO] --- xmlbeans-maven-plugin:2.3.3:xmlbeans (default) @ edoc-deeplink-intact-xml ---
17:53:29 warning: [options] bootstrap class path not set in conjunction with -source 1.4
17:53:29 error: Source option 1.4 is no longer supported. Use 6 or later.
17:53:29 error: Target option 1.4 is no longer supported. Use 1.6 or later.
但是我的有效 pom 似乎在 java 1.8 上,所以我不明白为什么会出现此错误。 这是有效的 pom:
<!-- ====================================================================== -->
<!-- -->
<!-- Effective POM for project -->
<!-- -->
<!-- ====================================================================== -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>parent-poms</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.0</version>
</parent>
<groupId>common</groupId>
<artifactId>my-xml-lib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<jdependMavenPluginVersion>2.0-beta-2</jdependMavenPluginVersion>
<jdk>1.8</jdk>
<jdk.arch>64</jdk.arch>
<jdk.vendor>redhat</jdk.vendor>
<jdk.version>1.8</jdk.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<mavenAntrunPluginVersion>1.7</mavenAntrunPluginVersion>
<mavenCheckstylePluginVersion>2.10</mavenCheckstylePluginVersion>
<mavenDeployPluginVersion>2.7</mavenDeployPluginVersion>
<mavenEnforcerPluginVersion>1.2</mavenEnforcerPluginVersion>
<mavenJavadocPluginVersion>2.9</mavenJavadocPluginVersion>
<mavenJxrPluginVersion>2.3</mavenJxrPluginVersion>
<mavenPluginPluginVersion>3.2</mavenPluginPluginVersion>
<mavenPmdPluginVersion>3.0.1</mavenPmdPluginVersion>
<mavenProjectInfoReportsPluginVersion>2.6</mavenProjectInfoReportsPluginVersion>
<mavenSourcePluginVersion>2.2.1</mavenSourcePluginVersion>
<mavenSurefirePluginVersion>2.15</mavenSurefirePluginVersion>
<mavenSurefireReportPluginVersion>2.14.1</mavenSurefireReportPluginVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<taglistMavenPluginVersion>2.4</taglistMavenPluginVersion>
<timestamp>2023-05-29T21:46:36Z</timestamp>
<versionsMavenPluginVersion>2.1</versionsMavenPluginVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<url>http://central</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<url>http://central</url>
</pluginRepository>
</pluginRepositories>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.3</version>
</extension>
</extensions>
<resources>
<resource>
<filtering>true</filtering>
<directory>C:\Data\my-xml-lib\src\main\resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<pushChanges>true</pushChanges>
<useEditMode>false</useEditMode>
<useReleaseProfile>true</useReleaseProfile>
</configuration>
</plugin>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>ISO-8859-1</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<versionRange>[2.3.3,)</versionRange>
<goals>
<goal>xmlbeans</goal>
<goal>xmlbeans-test</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<quiet>true</quiet>
</configuration>
</execution>
</executions>
<configuration>
<quiet>true</quiet>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
</plugin>
<plugin>
<groupId>com.google.code.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</execution>
</executions>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>regex-property</id>
<phase>validate</phase>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>shortGroupId</name>
<value>common</value>
<regex>^TOKEN\.(.+)</regex>
<replacement>$1</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<quiet>true</quiet>
</configuration>
</execution>
</executions>
<configuration>
<quiet>true</quiet>
</configuration>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration combine.self="override">
<releaseProfiles>release</releaseProfiles>
<workingDirectory>F:/Data/rel/${buildDefinitionId}/${buildLabel}</workingDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>about.html</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>jenkins-plugin</id>
<phase>validate</phase>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>1.8</version>
<vendor>redhat</vendor>
<arch>64</arch>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.8</version>
<vendor>redhat</vendor>
<arch>64</arch>
</jdk>
</toolchains>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
<goal>xmlbeans-test</goal>
</goals>
<configuration>
<schemaDirectory>//Path-to-schemaDirectory</schemaDirectory>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
<configuration>
<schemaDirectory>//Path-to-schemaDirectory</schemaDirectory>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>ISO-8859-1</encoding>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>ISO-8859-1</encoding>
</configuration>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>ISO-8859-1</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</execution>
</executions>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</project>
xmlbeans-maven-plugin 版本太旧。可以通过覆盖它的配置来使其与 java 8 一起使用,但不能与更高的 java 版本一起使用。尝试升级到新版本。
在浪费时间尝试多种事情之后,我发现问题是由于 org.codehaus.mojo:xmlbeans-maven-plugin[:2.3.3] 造成的。 这个答案https://github.com/ethercis/openehr-java-libs/issues/1似乎涵盖了我的情况。 如果您遇到此错误:
error: Source option 1.4 is no longer supported. Use 6 or later.
error: Target option 1.4 is no longer supported. Use 1.6 or later.
这似乎是插件试图在 1.4 中编译代码,而它应该使用更新的 jdk。这可以通过设置 xmlbeans-maven-plugin 的 javaSource 版本并添加 noJavac 标签以防止其使用正在使用的 jdk maven 来覆盖。
<javaSource>1.6</javaSource><!-- only "1.5+" is actually recognized, others values revert to "1.4" code -->
<noJavac>true</noJavac><!-- prevent XmlBeans from calling javac directly with "-source 1.6", which is unsupported on new Java versions -->
希望这可以帮助有同样问题的人。
注意:最终 XMLBeans 应更改为更新版本并使用更高版本提供的新插件,而不是 xmlbeans-maven-plugin[:2.3.3]。在我们的例子中,我们需要将此库移动到更新的 jenkin 服务器。