Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between runtime and compile group

Tags:

gradle

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?

like image 443
St.Antario Avatar asked Oct 22 '25 16:10

St.Antario


1 Answers

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

like image 115
BalRog Avatar answered Oct 26 '25 04:10

BalRog