The spring-boot-gradle-plugin will cause the error that Gradle can't download the latest SNAPSHOT dependency from maven nexus.
I use spring boot in my project and my project is build by Gradle. The project also has some SNAPSHOT dependencies inner our own company. But while I build the project, Gradle can't download the latest SNAPSHOT jars from my company's nexus server. If I remove spring boot from the project, Gradle can get the right latest jar. I think this is a bug that will affect the building seriously. Could you help to look into this? Thanks.
I tried Gradle version of 2.14.1, 2.7 and 3. All of them have this problem. Spring boot gradle plugin is 1.4.2 or 1.4.1.
I already use the following configuration as the official website provide:
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
But this configuration will only take affect while not use the spring boot. Once I use the spring boot, it will not take affect. I have spent much much much time on troubleshooting, but have no result.....
We can try to help, but we'll need some more information. A sample that reproduces the problem would be ideal.
OK, I will prepare a Sample ASAP and let you know. Thanks very much.
Please see the project. https://github.com/Leo-Lei/test-spring-boot-gradle-plugin The maven nexus repository can only be visit inner our company. So maybe your team need to test it in your own maven nexus server.
Thanks, but that project doesn't reproduce the problem. Perhaps you can update it, making use of a public repository that contains snapshots? If you can't do that, then please describe the problem in much more detail. We need to know exactly what is happening and exactly what you expected to happen. Seeing some output from your build would help with that.
Below is my testing scenario:
- There is a nexus server in our company.
- There are 2 projects A and B. Both of them are in
SNAPSHOTversion. Project B depends on A. - Assume that currently I didn't use
spring-bootorsprint-boot-gradle-pluginin project B. and the project A has a method test1(). - I build project A to generate an
A-1.0.0-SNAPSHOT.jarand publish it to nexus. - I build project B, Gradle will download the
A-1.0.0-SNAPSHOT.jarfrom nexus during build process, which has the test1() method. - Rename the method test1() to test2(), rebuild it and publish the new
SNAPSHOTjar to nexus. - I rebuild project B, and Gradle will get the latest
SNAPSHOTjar from nexus with the methodtest2(). Then repeat this operation, rename test2 to test3, publish project a to nexus, rebuild project b, to check if the latest A-Snapshot.jar is downloaded. Then rename test3 to test4 and do the same test. The result is that Gradle works fine and always get the latestA-SNAPSHOTjar from nexus, if there is nospring-bootorspring-boot-gradle-pluginin project. - Add spring-boot and
spring-boot-gradle-pluginto project. - Modify the method name ,for example, rename it from
test6totest7in project A, rebuild it and publish it to nexus. - Rebuild project B, I expect the latest snapshot jar will be downloaded from nexus, I.e., with the method name of test7. But the result is that the dependency
A-SNAPSHOTstill has the old methodtest6', rather thantest7. But the latest version of A in nexus has the method name oftest7'. So it seems Gradle didn't get the latest snapshot jar while the project use spring-boot or spring-boot-gradle-plugin.
In order to reproduce the problem, we need to update and publish a jar to some repository, we need read and write access, so it is hard to use of a public repository in the sample. Maybe setup a nexus repository in local is a good choice. Also I use the Intellij IDEA to build the project. I can see the exactly dependencies jars in the "External Libraries" window. If you don't use IDEA, maybe packing the project with all its dependencies to a JAR is a better choice to check if the latest SNAPSHOT jar is used or not.
It is late night in our time, I need to go home and have a rest.....Hope this update can clarify the problem. Thank you. Also I will update the sample tomorrow.
I have updated the sample. https://github.com/Leo-Lei/test-spring-boot-gradle-plugin
Thanks. You've only configured cacheChangingModulesFor on the configurations, you also need to configure dependency management with the same:
dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
thanks, wilkinsona. Could you please provide more details on where to add the configuration you provided. I try to add them in root place or in the dependencies block, but get the error "could not find method dependencyManagement()".
wilkinsona, sorry for my previous comment. I uncomment the spring-boot dependency stuff and have a try, it works. I have tried several times, and it seems now Gradle will get the latest snapshot jar. Thanks a lot. It resolve the problem and save me lot of time. At last, I have a question why I can't find the configuration that you provided in the Gradle official website or spring-boot official website?
And if I don't use spring-boot, this configuration is not needed. So I recommend the spring boot website to add this configuration on its official website for clarification. This is my kindly advice.
As described in the documentation, Spring Boot's Gradle plugin automatically applies the Dependency Management Plugin. We also link to its documentation where the configuration described above is already documented.
I got it, thanks for your help.
this really helps me, thanks!
thanks very mush. I also have this problem ... until found this.