I have a Maven project which, following a restart, has had a peculiar issue: it reports that there is no version field for one of the dependencies (apache-camel), even though the field is in fact populated. I have checked the pom.xml source, and confirmed that the field is in fact there and populated for all the dependencies. I am uncertain why m2e is saying otherwise. Is this a known issue, and if so, is there a specific fix for it?
The version of the m2e plugin is 1.5.1, and this is the parent POM for the project. Here is the dependencies section of POM file in question:
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>apache-camel</artifactId>
<type>pom</type>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<type>pom</type>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<type>pom</type>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-parent</artifactId>
<type>pom</type>
<version>3.0.0-M2</version>
</dependency>
</dependencies>
I had the same problem with m2e saying that the version field was not present.
In my case the version field was not the problem. Actually the problem was, that the dependency was defined twice.
Have you checked if the apache-camel or any other dependency (maybe also from a parent pom) is defined twice?
Related
The container 'Maven Dependencies' references non existing library 'C:\.m2\repository\com\portal\pcm\12.0.3\pcm-12.0.3.jar'
If i check the folder there are files that have the same name as the jar but end on jar.lastUpdated.
I tried maven clean and maven update which did not work. I delete the *.jar.lastUpdated in m2, but did not work too.
The line in my pom.xml is:
Missing artifact com.portal:pcm:jar:12.0.3
Missing artifact com.portal:pcmext:jar:12.0.3
Missing artifact com.portal:pcmext:jar:12.0.3
This block is the one with the marker where it states the artifact is missing.
<dependency>
<groupId>com.portal</groupId>
<artifactId>pcm</artifactId>
<version>12.0.3</version>
</dependency>
<dependency>
<groupId>com.portal</groupId>
<artifactId>pcmext</artifactId>
<version>12.0.3</version>
</dependency>
<dependency>
<groupId>com.portal</groupId>
<artifactId>pfc</artifactId>
<version>12.0.3</version>
</dependency>
I tried to use a version suggested by mvnrepository.com/artifact/com.portal.pcm/pcm/7.5, but didnt work too.
<dependency>
<groupId>com.portal.pcm</groupId>
<artifactId>pcm</artifactId>
<version>7.5</version>
</dependency>
<dependency>
<groupId>com.portal.pcm</groupId>
<artifactId>pcmext</artifactId>
<version>7.5</version>
</dependency>
<dependency>
<groupId>com.portal.pcm</groupId>
<artifactId>pfc</artifactId>
<version>7.5</version>
</dependency>
i guess dependency configuration is incorrect, but which is correct?
In my AWS lambda java project, I included the following snippet in my pom.xml.
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/bom -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.13.39</version>
<type>pom</type>
</dependency>
After I execute maven update on the project and try to import software.amazon.awssdk.* it shows an error message saying it can't find any such package.
Is it because the packages are not installed properly by maven?
The bom should go in a dependancy management
->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.13.39</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
A BOM is a list of versions for dependencies. It goes into <dependencyManagement>.
This means that a BOM does not add any dependencies to the project. DependencyManagement only fixes versions for dependencies that appear otherwise.
So you need to declare all relevant dependencies in your <dependencies> section.
What Google Maven dependency could fix this error:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:487)
at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:94)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:124)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
at java.io.InputStream.read(InputStream.java:101)
Code:
Blob blob = storage.get(blobId);
if(blob.exists()) {
return true;
}
Your Google guava version is either too old (< 20.0) or mismatched (multiple jars versions). Make sure you don't have several versions in your dependency tree.
Use
mvn dependency:tree | less
to look for the guava versions.
Please add following dependencies to your project's POM:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.8</version>
</dependency>
In my case, I happened to include both
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
and
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>
As it turns out, I cannot use both of these libraries. Removing google-collections fixed the issue for me.
Try inserting a dependency containing a newer version of guava at the top of your dependencies in your pom.xml containing your project.
E.g.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.1.1-jre</version>
</dependency>
For anybody encountering anything like this, i had the following pom:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
</dependency>
And commenting out the maven-shade plugin fixed it for me...
I had the same issue in my Java/Kotlin application. When the app was ran via IntelliJ there were no issues. However, when the .Jar was ran the error message above was thrown.
I could not find a direct action item to take with the Guava issue defined by #Laurent Perez above so I did the following which resolved the issue with my .Jar file running:
Removed .Jar IntelliJ configurations and file from IntelliJ. Then re-added the .Jar following Step 3 from this deploy guide.
Other actions to try if the above does not work:
Rebuild project.
Invalidate IntelliJ cache and restart.
Restart computer.
It happens when you're missing guava library from your dependency. Add it using following in your pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
Another reason could be there are multiple versions of google guava/collection library, you can't have both as mentioned by #sabbir in his comment, you ought to remove one of them.
Lastly it could be that some other dependency is dependent on the previous version of google guava/collections. Go to Dependency Hierarchy and search for google and see what all dependencies are dependent on the previous versions. In my case it was by version-maven-plugin, version 2.7
Here version-maven-plugin, version 2.7 uses google collections 1.0, and I require guava 24.0 Both can't work simuntaneously.
I excluded it in my pom.xml like this and then added a new dependency of guava
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
Resultant: Now google-collections is gone.
All
I am running into this error in my project when I updated aws library to the latest 1.11.3.
Caused by:
java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.<init>(ApacheHttpClientFactory.java:40)
at com.amazonaws.http.AmazonHttpClient.<clinit>(AmazonHttpClient.java:97)
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:145)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:393)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:373)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:355)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:339)
in my pom.xml
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kms</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-encryption-sdk-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Anyone know what I did wrong?
thanks
I had a similar issue with my grails application. In my case the ClassNotFoundException was being thrown from a deploy script. For me the reason SchemePortResolver wasn't being resolved implicitly was because it wasn't required at compile time, it was needed at runtime. Here's what I added to my BuildConfig.groovy to fix it:
runtime 'org.apache.httpcomponents:httpclient:4.5.2' //Required by BeanstalkDeploy.groovy at runtime
Since the OP's question was for Maven, here's the equivalent include:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<scope>runtime</scope>
</dependency>
If you add,
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
,it should work ok as it contains the missing class definitions.
A common cause would be a Maven dependency conflict. In the example below (pom.xml as viewed in Eclipse's Dependency Hierarchy tab), the POM explicitly includes v4.1 of httpclient, which forces Maven to omit the v4.5.5 that aws-java-sdk-core requires (and thus, causes the similar error java.lang.NoClassDefFoundError: org/apache/http/conn/DnsResolver at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory...):
In my case I delete the .meta file in eclipse workplace then import the project again thereafter it work like a charm.
Could not know where the problem exactly.
Before delete .meta I add all files from
aws-java-sdk-1.11.606\third-party\lib
In the pom.xml, i include logback & SLF4J like below, this works perfectly fine using maven build. It will give compilation error if i import directly from logback.
<dependencyManagement>
<dependencies>
<!-- We want to have slf4j with scope compile -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- logback we only want runtime, compiletime we want SLF4J -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
But how can I make eclipse honor the runtime scope of logback dependency and prevent import-suggestions from there?
Unfortunately it seems not to be possible on Eclipse with a normal build, as mentioned by #A4L, it is a known bug, check Bug 414645 and Bug 376616. Eclipse (m2e) can't properly manage Maven dependencies scope.
However, if you place the runtime dependencies on a profile, then Eclipse will not add them to the classpath (the profile shouldn't be active by default, though). I just tested it on Eclipse Mars and it works perfectly.
Hence, in your case you could add to your POM:
<profiles>
<profile>
<id>runtime</id>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
As such, it can't be used to compile on Eclipse. However, your build would then need to use it at runtime, running with -Pruntime in this case.
Although adapting your POM and build to an issue of an IDE might not be ideal, it could be a good compromise to achieve your goal.