Is there any impact if dependency was duplicated in pom.xml - maven

in pom.xml file, I found that the below dependency was repeated twice. Is there any bad impact if a dependency was defined multiple timese? Thanks.
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>batik</groupId>
<artifactId>batik-ext</artifactId>
<version>1.7</version>
</dependency>
<dependency>

that is not repeating, see the <artifactId>, if you really mean that you have duplicated dependencies, it doesn't harm but clean it up

Related

org.springframework.beans.factory.BeanDefinitionStoreException Failed to read candidate component class

I've read similar post but still cannot resolve this problem. I am using JDK 8 and Spring 5. So it's not due to version issue.
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [G:\githome\product-aggregation\target\classes\com\roger\product\ipc\viewobject\product\MultiUnitVO.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 90
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:454)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:275)
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:288)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 90
at org.springframework.asm.ClassReader.readUTF(ClassReader.java:2646)
at org.springframework.asm.ClassReader.readUTF8(ClassReader.java:2618)
at org.springframework.asm.ClassReader.readMethod(ClassReader.java:1110)
at org.springframework.asm.ClassReader.accept(ClassReader.java:729)
at org.springframework.asm.ClassReader.accept(ClassReader.java:527)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:65)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430)
... 20 common frames omitted
It's like this. I developed a maven plugin and included it in my project. This plugin is used to generate fields for specific classes in process-classes phase. To achieve this, I used ASM(version 5.0) to modify classes. Maven dependency like this:
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.roger</groupId>
<artifactId>permission</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>5.0</version>
</dependency>
Then I included it in my project.
<plugin>
<groupId>com.roger</groupId>
<artifactId>authorization-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>execution1</id>
<phase>process-classes</phase>
<goals>
<goal>addFieldPermission</goal>
</goals>
</execution>
</executions>
</plugin>
My project also has indirect dependency on ASM(version 5.0.4). I even upgraded ASM to 5.0.4(same as project), it's still going wrong.
I doubted that it's due to ASM conflict but have no idea how to fix it. Any idea?
EDIT Seems it has problem with the modified class. I debugged ClassPathScanningCandidateComponentProvider(spring-context-5.0.8) and found that exception thrown from line 430 just for the modified resources(as I said I added some fields in them by maven plugin). But I decompiled the modified classes using javap and found it's valid. I guess there is problem with the modified classes but don't know what's it.
As stated in the error log this is clear index out of bound exception.
Caused by: java.lang.ArrayIndexOutOfBoundsException: 90
Finally I got a temp solution. I made the fields public and removed the methods generated and everything goes well.
The generated methods are the root cause. When I keep only the generated fields, Spring Boot started up successfully. Seems javassist 3.12.1.GA might go wrong with JDK 1.8. I will further investigate.

Find all dependencies that include a given package

I excluded an artifact because it causes conflicts, namely the jsr311-api given below. Yet when I run the generated jar I'm still getting the java.lang.NoSuchMethodError error. I suspect that another dependency is also including this artifact. How can I find out which one? My dependency list is quite large. Which dependencies include the package javax.ws.rs.core?
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.7.3</version>
<exclusions>
<!-- Causes java.lang.NoSuchMethodError: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family; -->
<exclusion>
<artifactId>jsr311-api</artifactId>
<groupId>javax.ws.rs</groupId>
</exclusion>
</exclusions>
</dependency>
Go to
http://search.maven.org/#advancedsearch%7Cgav
and use classname search to find
javax.ws.rs.core.Response
If you use a Nexus 2.x in your company, you can use classname search there as well.
If you want to find out where a given artifact (that you e.g. found by classnmae search) comes from, use dependency:tree in Maven.
In my case the mistake was that I had to manually add the javaee api and I set <scope>provided</scope> which was a mistake, fixing this solved the problem.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope><!-- remove this -->
</dependency>

Why is cxf-rt-transports-http needed *twice* in a pom.xml

Adding the following snippet to my code:
Message message = PhaseInterceptorChain.getCurrentMessage();
HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
request.getRemoteAddr();
Created a situation in which I had to add the following dependency (cxf.version is defined as 2.7.1):
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
Although I already had earlier in my pom.xml the following:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
If I don't add that later dependency, the project will not build, complaining "package org.apache.cxf.transport.http does not exist".
If I remove the earlier one (the one with <scope>runtime</scope>), the project will build successfully but the .war will fail to deploy with ClassNotFoundException: org.apache.cxf.endpoint.AbstractEndpointFactory.
Why are 2 occurrences of the same exact groupId/artifactId/version needed in the same pom.xml?
How do I clean/tidy up my pom.xml so that this package is only listed once?
Problem solved. For the benefit of all I am providing the solution.
All I did was to remove that apparent redundancy was to move the earlier one (i.e. with <type>jar</type>) down, replacing the second one and removing the <scope> line. Thus, remaining with only:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
<type>jar</type>
</dependency>
But further down the dependencies list.
It appears that the order of dependencies does matter (please correct if you know otherwise).

neo4j.test: "package org.neo4j.test does not exist" error in maven

I have small question: when I add dependency
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>1.8.1</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
to maven, I have error:
package org.neo4j.test does not exist
Why?
I didn't find "neo4j.test" in maven repository (http://search.maven.org/).
TIA.
Eugeny
If your actual code is underneath src/main/java, then the scope should not be test. Otherwise, please provide more details.
I don't use Maven but I copy the jar from http://m2.neo4j.org/content/groups/everything/org/neo4j/neo4j-kernel/1.8.1/neo4j-kernel-1.8.1-tests.jar
You need to use the classifier element:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>1.8.1</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Some read: http://maven.apache.org/pom.html#Maven_Coordinates

Maven: Package "brother" projects

I am working on a big set of projects strongly related to each other and looking for a way to reduce to minimimun the maintenance overhead using a good maven configuration.
One of the scenarios which I am currently working on is a set of several small projects inside the same "company project", most of them depending on the others, with a big list of external dependencies in each one.
In order to make it cleaner I created a parent pom, set all of them as modules and created a big list of dependencies inside the parent's dependencyManagement section allowing me to remove most of the version tags inside the project poms.
The next stage for me is to reduce the amount of resulting jars by making use of some plugin, such as one-jar or assembly, in oder to get a signle jar from one of those projects containing all the others inside. However, this led me to having an enourmous jar with tons of external libraries inside, most of them already provided by the running environment.
I know that adding the <scope>provided</scope> tag to the declaration of external dependencies would do the job, but I would like to avoid having dozens of these tags in my poms.
So the questions are:
Is there any way to define a default scope, so I can use compile scope only in the libs which I want included?
Then, instead of having this:
<dependencyManagement>
<dependency>
<groupId>any.external</groupId>
<artifactId>lib</artifactId>
<version>1.0</version>
<scope>provided</scope> <!--Skip Inclusion-->
</dependency>
<dependency>
<groupId>any.external</groupId>
<artifactId>cool-lib</artifactId>
<version>1.0</version>
<scope>provided</scope> <!--Skip Inclusion-->
</dependency>
<dependency>
<groupId>another.external</groupId>
<artifactId>lib</artifactId>
<version>1.0</version>
<scope>provided</scope> <!--Skip Inclusion-->
</dependency>
<dependency>
<groupId>my.company</groupId>
<artifactId>some-dependency</artifactId>
<version>1.0</version>
</dependency>
</dependencyManagement>
I could have this (note that the difference will come when we have only 10 internal projects to include, but more than 100 external libs):
<dependencyManagement>
<dependency>
<groupId>any.external</groupId>
<artifactId>lib</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>any.external</groupId>
<artifactId>cool-lib</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>another.external</groupId>
<artifactId>lib</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>my.company</groupId>
<artifactId>some-dependency</artifactId>
<version>1.0</version>
<scope>compile</scope><!-- Include It! -->
</dependency>
</dependencyManagement>
Or better: Maybe I'm skipping something and there is already a way to tell maven: "Include only the jars generated within the current project"?
Remember that all modules are "brothers", included as modules of the same parent, and compiled at the same time.
Many thanks in advance!
Carles

Resources