Incompatibility between Maven3 and Maven2

Original link: http://afoo.me/posts/2023-03-14-maven3-trap.html

20230314220910.png

Incompatibility between Maven3 and Maven2 – Mr. Fuqiang said: the thinking and precipitation of an architect

Incompatibility between Maven3 and Maven2

Wang Fuqiang

2023-03-14



20230314220910.png

The problem started from the failure of the code completion function in Intellij IDEA. At first, I suspected that it was a problem with the newly upgraded IDE version, and also suspected that it was a problem with the newly upgraded Scala plug-in. Finally, I found out that it was a fucking Maven problem. …

1 Troubleshooting principles and solutions

After the Maven3.x version, a new meta-information file _remote.repositories was added, which caused the artifact of my local mvn clean install not to be found when compiling with IDE and maven.

Although this mechanism solves some problems (some group:artifact conflicts), it should not have such a result!

The solution is to remove this meta-information file. You can remove only one artifact or all of them. For example, use the following command:

 cd ~/.m2 find . -name "_remote.repositories" -type f -delete

Oneliner also has: find ~/.m2/repository -name _remote.repositories -exec rm -v {} \;

In the previous version of Maven3, sometimes the name of the meta information file is _maven.repositories , so the following commands are also useful:

 find ~/.m2/repository -name _maven.repositories -exec rm -v {} \;

When the author encountered this problem, it was 3.8.2:

 LuckinJohn ➜ youtubemp3 git:(master) ✗ mvn --version Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f) Maven home: /Users/fq/bin/apache-maven-3.8.2 Java version: 19.0.2, vendor: Oracle Corporation, runtime: /Users/fq/Library/Java/JavaVirtualMachines/openjdk-19.0.2/Contents/Home Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "13.2.1", arch: "x86_64", family: "mac"

But it is annoying to manually remove this file after each mvn install. Therefore, in addition to manually removing the meta-information file, there is another way to avoid the problem that the local install library cannot be recognized, that is, to execute mvn clean install Add a parameter to mvn clean install :

 mvn clean install -Daether.enhancedLocalRepository.trackingFilename=_ignore_remote.repositories

The effect of this parameter is to generate a meta-information file named _ignore_remote.repositories instead of the default _remote.repositories , so that maven3 will not have the problem of not being able to recognize the local new install library.

20230314215642.png

Of course, this file name can be written casually, as long as it is not _remote.repositories .

2 digressions

I also encountered a few tricky problems today:

2.1 The problem that the spring boot version is too low

 2023-03-14 20:32:11,708 WARN [main] oscaAnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/Users/fq/workspace.keevol/KeeboxNative/target/keeboxfx-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/keevol/keebox/annotations/ConfigSetting.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: URL [jar:file:/Users/fq/workspace.keevol/KeeboxNative/target/keeboxfx-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/keevol/keebox/annotations/ConfigSetting.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 63 2023-03-14 20:32:11,755 ERROR [main] osboot.SpringApplication - Application run failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/Users/fq/workspace.keevol/KeeboxNative/target/keeboxfx-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/keevol/keebox/annotations/ConfigSetting.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: URL [jar:file:/Users/fq/workspace.keevol/KeeboxNative/target/keeboxfx-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/keevol/keebox/annotations/ConfigSetting.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 63

After upgrading to the latest version, too.

But later I found that when I exited the program, the life cycle of spring boot and the life cycle of the bean had been mismatched, causing an exception. Although I exited the program, it was still an eyesore. In the end, I killed all spring boot directly. After all, KEEBOX is a desktop program. , In fact, there is no need for a server-side framework such as spring boot.

2.2 vertx version conflict problem

The error is similar to:

 java.lang.NoSuchMethodError: 'void io.vertx.core.http.HttpServerResponse.end(java.lang.String)'

Some people suggested that it was caused by version inconsistencies , so mvn dependency:tree , and then checked the class libraries that depended on vertx. Finally, I found that the kapi developed earlier relied on the old 3.xx version of vertx, and removed it. Get it done later.



Subscribe to "Fu Bao Premium Subscription"


Twitter-logo.png
© Fuqiang Wang Personal Copyright, All Rights Reserved.
Copyright © Fuqiang Wang All rights reserved – Since 2004

Everything is homebrewed with pandoc and Markdown , little Scala also included.

This article is transferred from: http://afoo.me/posts/2023-03-14-maven3-trap.html
This site is only for collection, and the copyright belongs to the original author.