1. What is it ?
- Gradle is an advanced build management system
- Gradle supports the automatic download and configuration of project dependencies (libraries)
- A project using Gradle is described via build.gradle
2. Dependency management
Dependency management is compsed of two pieces : dependencies and publications
- this is what Gradle need to know so he can build or run your project.
- these incoming files are called dependencies
- Gradle allows you to tell what are the dependencies of the project so that he can take care of finding these dependencies and make them availeable for your project
- the dependencies might be downloaded from Maven or Ivy repository or located in local directory or may be need to be build by another project in your multiproject build. this is called dependency resolution
- notice that you need only to tell to tell Gradle the name of the dependency and it will find it
publications
- Gradle need to build and upload the things that your project produce. this is called publications
- publication may be to put the app on the local disk , or may be upload it to remote maven or Ivy repository . this process is called publication
3. Decalring your dependency
example :
build.gradle
apply plugin: 'java' repositories { mavenCentral() } dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' testCompile group: 'junit', name: 'junit', version: '4.+' }
- hibernate core 3.6.7 Final will be used for compilation
- junit version > 4.0 will be used to compile the tests
- Gradle will look for dependencies like hibernate in Maven central respository
4. Dependency Configurations
Gradle's dependencies is grouped into configurations.
The java plugin defines number of standard configurations :
- compile - the dependencies required to compile the production source of the project
- runtime - the dependencies required by the production classes at runtime. By default includes also the compiled time dependencies
- testCompile - the dependencies required to compile the test source of the project. By default includes also the compiled production classes and compiled time dependencies
5. External Dependencies
This dependency relate to file build and stored outside (e.g. on Maven or Ivy repository or local directory) the current build.
example :
build.gradle
dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' }
an external dependency is defined by : group , name and version attributes
You can however use a shortcut : group.name.version as follows :
build.gradle
dependencies {
compile 'org.hibernate:hibernate-core:3.6.7.Final'
}
6. Repositories
- Gradle looks for files for you , where does it find them ? in repositories
- respositories are actually a collection of files organized by : group , name and version.
- Gradle understands few repositories formats : Maven , Ivy and several ways for accessing the repository such as the local directory of HTTP.
an eaxample of using Maven central repository
build.gradle
repositories { mavenCentral() }
7. References
Nathan
No comments:
Post a Comment