In a gradle build script I've the following piece of code:
dependencies {
runtime group: 'org.springframework', name: 'spring-core', version: '4.1.1'
}
and it works fine, but if I change it to
dependencies {
compile group: 'org.springframework', name: 'spring-core', version: '4.1.1'
}
an exception will be thrown during gradle build
Could not resolve all dependencies for configuration ':compile'.
> Could not find org.springframework:spring-core:4.1.1.
Searched in the following locations:
https://repo1.maven.org/maven2/org/springframework/spring-core/4.1.1/sprin
g-core-4.1.1.pom
https://repo1.maven.org/maven2/org/springframework/spring-core/4.1.1/sprin
g-core-4.1.1.jar
I thought the artifact searching for in the same place for both compile and runtime. What are differences between them?
Gradle resolves compile dependencies before it performs compilation, expecting that the source code will reference the artifact directly. However, it does not resolve runtime dependencies until later in the build process. (See @Dónal 's answer for usage guidelines in choosing between compile and runtime)
Thus, it is most likely that the difference between the two cases is that your build task required compilation, but not runtime prep. With your original configuration, any task requiring runtime prep would have failed with the same error.
To fix the failure in this specific case, I recommend changing your version value from 4.1.1 (which is not in the Maven repository you reference) to 4.1.1.RELEASE (which is).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With