Skip to content

Commit b5810e1

Browse files
Major v2.0.0 release:
* New configuration DSL, closer to original gradle dependencies. * Updated credentials handling, using new properties. * Fixed problem with cached singletons. * Dropped SVN support.
1 parent e628b20 commit b5810e1

24 files changed

+820
-799
lines changed

README.md

Lines changed: 99 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
GradleVcsDependencyPlugin
2-
=========================
1+
GradleGitDependencies
2+
=====================
33

44
[![Maven Central][mvn-img]][mvn-url]
55

6-
Gradle plugin to add external Git and SVN repositories as dependencies.
6+
Gradle plugin to add external git repositories as dependencies.
77

8-
### How to use ###
8+
### Setup ###
99

1010
In `settings.gradle` file add the following lines:
1111

@@ -14,96 +14,123 @@ In `settings.gradle` file add the following lines:
1414
jcenter()
1515
}
1616
dependencies {
17-
classpath 'com.alexvasilkov:gradle-vcs-dependency:1.1.1'
17+
classpath 'com.alexvasilkov:gradle-git-dependencies:2.0.0'
1818
}
1919
}
2020

21-
apply plugin: 'com.alexvasilkov.vcs-dependency'
21+
apply plugin: 'com.alexvasilkov.git-dependencies'
2222

2323
Optionally you can provide settings next in `settings.gradle`:
2424

25-
vcs {
26-
dir = 'libs' // Directory in which to store vcs repositories, 'libraries' by default
27-
cleanup = false // Whether to cleanup unused dirs inside 'libraries' dir, true by default
25+
git {
26+
dir 'libs' // Directory in which to store git repositories, 'libs' by default
27+
cleanup true // Whether to cleanup unused dirs inside 'libs' dir, true by default
2828
}
2929

30-
Now in `build.gradle` add the following method:
30+
### Usage ###
3131

32-
def vcs() {
33-
git name: 'GitDependencyName',
34-
url: 'https://example.com/repository.git',
35-
commit: '12345678abcdefgh'
32+
Now in `build.gradle` add the following:
3633

37-
svn name: 'SvnDependencyName',
38-
url: 'https://example.com/repository',
39-
rev: 123
34+
git {
35+
implementation 'https://example.com/repository.git', {
36+
name 'DependencyName'
37+
commit '12345678abcdefgh'
38+
}
4039
}
4140

42-
Supported parameters:
43-
44-
| Parameter | Description |
45-
| --------- | ----------- |
46-
| name | Dependency name, will be used as Gradle dependency name and as source code directory name. Required. |
47-
| url | Git (or SVN) repository url. Required. |
48-
| path | Path within repository which should be added as dependency. For example `/library/`, `/trunk/`. |
49-
| commit | Git commit id of any length, tag name, branch name. For example `v1.2.3` or `master`. Required for Git. |
50-
| rev | SVN revision number or 'HEAD'. Required for SVN. |
51-
| dir | Repository directory, overrides global directory settings. |
52-
| username | Username to access repository. |
53-
| password | Password to access repository. |
54-
| authGroup | Group name (prefix) used when looking for access credentials. See `Credentials` section for more details. Default is `VCS`. |
55-
| noAuth | Whether authentication is required for this repository. Default value is `true` meaning that missing credentials will fail build process. |
56-
| includeProject | Whether to include this repository as Gradle project or not. Can be set to `false` if you only want this repository to be fetched before building main project. Default is `true`. |
57-
| keepUpdated | Whether to update this repository automatically or not. Default is `true`. |
58-
| configName | Gradle dependency configuration name. For example `compile`, `implementation`, `api`. Default value is `implementation`. |
59-
60-
Note, that using 'master' as git commit or 'HEAD' as svn revision is not recommended, use explicit commit / revision instead.
61-
62-
63-
### Example ###
64-
65-
def vcs() {
66-
git name: 'GestureViews',
67-
url: 'https://github.com/alexvasilkov/GestureViews.git',
68-
commit: 'v2.5.1',
69-
path: '/library',
70-
noAuth: true
41+
Where `implementation` is a configuration name, similar as used for regular gradle dependencies.
42+
Can be any valid configuration name.
43+
44+
#### Supported parameters ####
45+
46+
| Parameter | Description |
47+
| --------------- | ----------- |
48+
| name | Dependency name. Will be used as gradle project name and as repo directory name. If the name is not set then it will be taken from url. |
49+
| commit | Git commit id of any length, tag name or branch name. For example `e628b205`, `v1.2.3`. Set to `master` by default. |
50+
| tag | Same as `commit`, see above. |
51+
| branch | Same as `commit`, see above. |
52+
| dir | Directory for cloned repository. Used to override default directory as defined in `settings.gradle`. |
53+
| projectPath | Path within repository which should be added as gradle project. By default repo's root directory is added as project. |
54+
| username | Username to access repository. See `Credentials` section below. |
55+
| password | Password to access repository. See `Credentials` section below. |
56+
| authGroup | Group name used when looking for credentials. See `Credentials` section below. |
57+
| keepUpdated | Whether to update this repository automatically or not. Default is `true`. |
58+
59+
Note that using `master` or any other branch name as git commit is not recommended,
60+
use explicit commit or tag instead.
61+
62+
63+
You can also specify git repos in `settings.gradle` similar as it is done in `build.gradle`
64+
but use `fetch` instead of configuration name:
65+
66+
git {
67+
fetch 'https://example.com/repository.git', {
68+
dir '$rootDir/gradle/scripts'
69+
tag 'v1.2.3'
70+
}
7171
}
7272

73+
Such repositories will be downloaded but not added as dependencies.
74+
This can be useful, for example, if you want to pre-fetch build scripts.
7375

74-
### How it works ###
76+
### Examples ###
7577

76-
1. You're providing dependency name, Git or SVN repository URL and other details in `build.gradle` file.
77-
1. Plugin clones repository to `libraries/[NAME]` project directory (can be changed, see further)
78-
at specified commit (Git) or revision (SVN).
79-
1. Cloned repo will be included as sub-project and necessary dependency will be added to original project.
80-
1. Dependencies are resolved recursively, for example your Git dependency can have other Git or SVN dependencies.
81-
1. If several projects have dependencies with same name then dependencies info and versions
82-
should be completely the same. Otherwise plugin will fail build process.
83-
1. Plugin automatically updates repository if version info was updated. But if there are any uncommited
84-
changes in local repo then plugin will fail build process until you manually resolve conflicts.
85-
1. Removed dependencies will be automatically cleaned from `libraries` directory (can be changed, see further).
78+
git {
79+
implementation '[email protected]:alexvasilkov/GestureViews.git'
8680

81+
api 'https://github.com/alexvasilkov/GestureViews.git', {
82+
name 'GestureViews'
83+
tag 'v2.6.0'
84+
projectPath '/library'
85+
}
86+
}
87+
88+
89+
### How it works ###
90+
91+
1. You're providing git repository URL and other optional details in `build.gradle` file.
92+
2. The plugin clones repository to `libs/[name]` directory (both name and directory can be changed)
93+
at specified commit, tag or branch.
94+
3. Cloned repo will be included as sub-project and defined as dependency of original project.
95+
4. Dependencies are resolved recursively, i.e. your git dependency can have other git dependencies.
96+
5. If several projects have dependencies with same name then all other details (url, commit, etc)
97+
should be completely the same, otherwise build process will fail.
98+
6. Plugin automatically updates repository if `commit` does not much local commit. If there are any
99+
uncommited changes in local repo then build process will fail until you manually resolve conflicts.
100+
7. Removed dependencies will be automatically cleaned from `libs` directory.
87101

88102
### Credentials ###
89103

90-
If `username` property is not specified, plugin will look first for property named
91-
`[name in upper case]_USERNAME` and then for property `[authGroup]_USERNAME`
92-
(`VCS_USERNAME` by default) in next places:
104+
If git repo is using SSH url (starts with `git@`) then the plugin will automatically try to use
105+
local SSH key. But you need to ensure your SSH key is correctly setup, see instructions for
106+
[GitHub](https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh)
107+
or [Bitbucket](https://confluence.atlassian.com/bitbucket/ssh-keys-935365775.html)
108+
109+
If git repo is using HTTPS url then there are two options how you can define credentials:
110+
111+
* Using `username` and `password` options directly in `build.gradle`.
112+
* Using `authGroup` option and providing credentials as specified below.
113+
114+
If `authGroup` is provided then the plugin will search for `git.[authGroup].username` and
115+
`git.[authGroup].password` params in:
116+
117+
* command line arguments (e.g. `[email protected]`)
118+
* gradle.properties
119+
* local.properties
120+
* ~/.gradle/gradle.properties
121+
* environment variables, in uppercase and with `_` instead of `.`, e.g. `GIT_GITHUB_USERNAME`
93122

94-
1. `vcs.properties` in the root directory of the project
95-
1. `gradle.properties` in the root directory of the project
96-
1. `gradle.properties` in `[USER_HOME]/.gradle/` directory
97-
1. Environment variables
98123

99-
If `password` property is not specified, plugin will look first for property named
100-
`[name in upper case]_PASSWORD` and then for property `[authGroup]_PASSWORD`
101-
(`VCS_PASSWORD` by default) in same places.
124+
### Migration from v1.x.x ###
102125

103-
For example, if `name` property is set to `ProjectName` and `authGroup` property set to `Company`
104-
then plugin will first look for properties called `PROJECTNAME_USERNAME` and `PROJECTNAME_PASSWORD`.
105-
If no credentials found then plugin will check properties `COMPANY_USERNAME` and `COMPANY_PASSWORD`.
126+
There were several breaking changes since version 1.x.x:
106127

128+
* Default directory is changed from `libraries` to `libs`.
129+
* Instead of defining `def vcs() { ... }` method you can use simpler `git { ... }`
130+
* Git dependencies declaration is reimplemented to mimic default gradle dependencies section.
131+
* Credentials properties names are changed, e.g. was `GIT_AUTHGROUP_USERNAME`,
132+
become `git.authGroup.username`.
133+
* Dropped SVN support.
107134

108135
#### License ####
109136

@@ -119,5 +146,5 @@ If no credentials found then plugin will check properties `COMPANY_USERNAME` and
119146
See the License for the specific language governing permissions and
120147
limitations under the License.
121148

122-
[mvn-url]: https://maven-badges.herokuapp.com/maven-central/com.alexvasilkov/gradle-vcs-dependency
123-
[mvn-img]: https://img.shields.io/maven-central/v/com.alexvasilkov/gradle-vcs-dependency.svg?style=flat-square
149+
[mvn-url]: https://maven-badges.herokuapp.com/maven-central/com.alexvasilkov/gradle-git-dependencies
150+
[mvn-img]: https://img.shields.io/maven-central/v/com.alexvasilkov/gradle-git-dependencies.svg?style=flat-square

build.gradle

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
apply plugin: 'groovy'
22

3-
tasks.withType(GroovyCompile) {
4-
sourceCompatibility = '1.7'
5-
targetCompatibility = '1.7'
6-
}
7-
83
repositories {
94
jcenter()
105
}
116

127
dependencies {
138
compile gradleApi()
149
compile localGroovy()
15-
16-
compile 'org.tmatesoft.svnkit:svnkit:1.9.2'
17-
compile 'org.ajoberstar:grgit:1.9.3'
10+
compile 'org.ajoberstar.grgit:grgit-core:4.0.2'
1811
}
1912

20-
// Build & upload: './gradlew clean build uploadArchives'
21-
apply from: "${rootDir}/gradle/scripts/gradle-plugin-mvn-push.gradle"
13+
// Build & upload: './gradlew clean build publish'
14+
apply from: "$rootDir/gradle/scripts/publish.gradle"

gradle.properties

Lines changed: 0 additions & 17 deletions
This file was deleted.

gradle/scripts/gradle-plugin-mvn-push.gradle

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)