spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

The spring-boot-gradle-plugin will cause the error that Gradle can't download the latest SNAPSHOT dependency from maven nexus.

Open leiwei2094 opened this issue 10 years ago • 15 comments

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.

leiwei2094 avatar Nov 17 '16 11:11 leiwei2094

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.....

leiwei2094 avatar Nov 17 '16 11:11 leiwei2094

We can try to help, but we'll need some more information. A sample that reproduces the problem would be ideal.

wilkinsona avatar Nov 17 '16 11:11 wilkinsona

OK, I will prepare a Sample ASAP and let you know. Thanks very much.

leiwei2094 avatar Nov 17 '16 12:11 leiwei2094

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.

leiwei2094 avatar Nov 17 '16 12:11 leiwei2094

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.

wilkinsona avatar Nov 17 '16 12:11 wilkinsona

Below is my testing scenario:

  1. There is a nexus server in our company.
  2. There are 2 projects A and B. Both of them are in SNAPSHOT version. Project B depends on A.
  3. Assume that currently I didn't use spring-boot or sprint-boot-gradle-plugin in project B. and the project A has a method test1().
  4. I build project A to generate an A-1.0.0-SNAPSHOT.jar and publish it to nexus.
  5. I build project B, Gradle will download the A-1.0.0-SNAPSHOT.jar from nexus during build process, which has the test1() method.
  6. Rename the method test1() to test2(), rebuild it and publish the new SNAPSHOT jar to nexus.
  7. I rebuild project B, and Gradle will get the latest SNAPSHOT jar from nexus with the method test2(). 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 latest A-SNAPSHOT jar from nexus, if there is no spring-boot or spring-boot-gradle-plugin in project.
  8. Add spring-boot and spring-boot-gradle-plugin to project.
  9. Modify the method name ,for example, rename it fromtest6 to test7 in project A, rebuild it and publish it to nexus.
  10. 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-SNAPSHOT still has the old method test6', 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.

leiwei2094 avatar Nov 17 '16 13:11 leiwei2094

I have updated the sample. https://github.com/Leo-Lei/test-spring-boot-gradle-plugin

leiwei2094 avatar Nov 18 '16 04:11 leiwei2094

Thanks. You've only configured cacheChangingModulesFor on the configurations, you also need to configure dependency management with the same:

dependencyManagement {
    resolutionStrategy {
        cacheChangingModulesFor 0, 'seconds'
    }
}

wilkinsona avatar Nov 18 '16 09:11 wilkinsona

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()".

leiwei2094 avatar Nov 19 '16 04:11 leiwei2094

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?

leiwei2094 avatar Nov 19 '16 07:11 leiwei2094

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.

leiwei2094 avatar Nov 19 '16 07:11 leiwei2094

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.

wilkinsona avatar Nov 19 '16 11:11 wilkinsona

I got it, thanks for your help.

leiwei2094 avatar Nov 20 '16 01:11 leiwei2094

this really helps me, thanks!

isaacdong avatar Dec 06 '16 12:12 isaacdong

thanks very mush. I also have this problem ... until found this.

starflash avatar Nov 02 '17 09:11 starflash