maven - How to avoid putting a specific version of Spring Boot in a library -
i developing library based on spring boot, used in multiple spring boot applications. library supposed work spring boot 1.3.0.m1
onwards.
i thinking how avoid putting specific version of spring jars in it, , instead let application specify exact version. have come out solution, seems work except combinations:
in library, have spring boot version
1.3.0.m1
, , have scope of dependenciesprovided
. 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 application, mention actual spring boot version, e.g.
1.3.0.m3
, , re-include dependencies, 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 run application 1.3.0.m1
+1.3.0.m3
specific combination, i'm getting error, think compatibility issue:
exception in thread "main" java.lang.nosuchmethoderror: org.springframework.core.resolvabletype.forinstance(ljava/lang/object;)lorg/springframework/core/resolvabletype;
however, experimenting stable releases, e.g. when set lib version 1.2.0.release
, app version 1.2.5.release
, works.
so, wondering whether right way handle such scenario, or there better way.
you're mixing optional dependencies , dependency management. if library requires spring boot run, must specify dependencies default scope.
if user doesn't , import library, he'll 1.3.0.m1
because that's available default.
if create project start.spring.io using instance 1.3.0.m3
, add library it, you'll see project using 1.3.0.m3
. because project has dependency management section enforces use of spring boot 1.3.0.m3
.
in other words, user has specify version of library wants use; library developer, there nothing you can do.
regarding error, impossible figure out you're doing best guess trying override both spring framework , spring boot incompatible versions. may want review , better understand dependency management is. this question starting point.
Comments
Post a Comment