Issue with resolving methods from concrete classes using Gradle build

gradle-3297

(kakarotto) #1

I am trying to use a logger in a subproject. The dependency for this is defined in the subprojects { … } space of my parent gradle.build. My settings.gradle includes the subproject containing the below code. The issue is that I am unable to use an dependencies that provide a concrete implementation of any interface, abstract class or just extends a class to add more methods. For example:
In my subproject,

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Abc {
private static final Logger LOGGER = LoggerFactory.getLogger(Abc.class);
public void method1() {
LOGGER.info(“Number of entries found for id {} in system is {} of {} expected”,id, system.size(), systemCount);
//Here, it says that the method info with varargs method parameters is not found and I get an error in this line.

}
}

/*
Actual error reported by gradle build
C:\GIT\dir1\dir2\dir3\src\main\java\com\something\Abc.java:647: error: no suitable method found for info(String,String,int,int)
LOGGER.info(“Number of entries found for id {} in system is {} of {} expected”,id, system.size(), systemCount);;
^
*/

I am using Gradle 3.4 directly without a wrapper. The build.gradle files were generated from maven POMs using gradle init and it works fine with maven. I also double checked to make sure all the dependencies were equivalent to that of maven’s.


(kakarotto) #2

This got fixed by removing a dependency from the build.gradle file.
So spring-core and apacheds are two artifacts that both have a class with exact same fully qualified name i.e. org.springframework.util.CollectionUtils. The issue was that CollectionUtils was being picked up from apacheds instead of spring-core. I removed apacheds from the build.gradle and everything got fixed. Even the above stated logger issue got resolved. However, I am still wondering about two things:

  1. How come maven did not complaint about this?
  2. What should I have done if I could not afford to remove the apacheds dependency from my build.gradle? Is there a way to force gradle to pick up classes from a specific jar?