I am developing a library based on Spring Boot, which could be used in multiple Spring Boot applications. The library is supposed to work with Spring Boot 1.3.0.M1
onwards.
I was thinking how to avoid putting a specific version of Spring JARs in it, and instead let the application specify the exact version. Currently I have come out with this solution, which seems to work except with certain combinations:
In the library, have the Spring Boot version as
1.3.0.M1
, and have the scope of all the dependencies asprovided
. Like this:... <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.0.M1</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <scope>provided</scope> </dependency> ...
In the application, mention the actual Spring Boot version, e.g.
1.3.0.M3
, and re-include all the dependencies, like this:... <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.0.M3</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> ...
When I run the application with this 1.3.0.M1
+1.3.0.M3
specific combination, I'm getting this error, which I think is just some compatibility issue:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.ResolvableType.forInstance(Ljava/lang/Object;)Lorg/springframework/core/ResolvableType;
However, experimenting with stable releases, e.g. when I set the lib version to 1.2.0.RELEASE
and the app version to 1.2.5.RELEASE
, it works.
So, I was wondering whether this would be the right way to handle such scenario, or there is a better way.