Reputation: 95
I want to use a class and in my pom there are two dependencies that support it: dependency1 and dependency2. Using the class with dependency1 crashed my program, so I deleted it completely from pom and left dependency2 as it was and the code was working. How do I tell maven to build my class with dependency2 and not dependency1, without deleting dependency1 (in case dependency1 contains something that I want to use in my code later on)?
Upvotes: 0
Views: 853
Reputation: 35853
You cannot sensibly use two libraries that contain classes with the same qualified class names.
So
Upvotes: 1
Reputation: 1491
It's very unlikely to have the same class with same package name on two different dependencies.Because artifactIds are unique for each dependency even it belongs to the same groupdId. So if you solved your issue by using the dependency2's class then that's the class you need. And as you asked if you need dependency1 for any other task keeping the dependency1 on your pom.xml won't be a problem.Only thing that you need to take care is importing the class that you need exactly from dependency2.So please check your import statements in the class and see if it's importing the class from dependency2.
Upvotes: 1
Reputation: 615
when you are importing the dependency in your respective class just check for the entire address of the dependency (the whole package structure) and make sure that you are using the dependency from the dependency2.
Also, if you have removed dependency1 from the pom.xml, maven will not put the dependency1 in the target folder which will be generated while building the project.
Upvotes: 1