Android Gradle에서 git 저장소를 종속성으로 선언 할 수 있습니까?
mavencentral에서 내 lib의 마스터 버전을 사용하고 싶습니다.
Android Gradle에서 git 저장소를 종속성으로 선언 할 수 있습니까?
나에게 가장 좋은 방법은 다음과 같습니다.
1 단계. 리포지토리 끝에있는 build.gradle에 JitPack 리포지토리를 추가합니다.
repositories {
// ...
maven { url "https://jitpack.io" }
}
2 단계. 양식에 종속성 추가
dependencies {
compile 'com.github.User:Repo:Tag'
}
다음과 같이 마스터 브랜치에서 최신 커밋을 빌드 할 수 있습니다.
dependencies {
compile 'com.github.jitpack:gradle-simple:master-SNAPSHOT'
}
또는 다음과 같은 하위 모듈로 저장소를 등록 할 수 있습니다.
$ git submodule add my_sub_project_git_url my-sub-project
그런 다음 settings.gradle 파일에 다음과 같은 프로젝트를 포함합니다.
include ':my-app', ':my-sub-project'
마지막으로 다음과 같이 애플리케이션 build.gradle 파일에서 프로젝트를 종속성으로 컴파일하십시오.
dependencies {
compile project(':my-sub-project')
}
그런 다음 프로젝트를 복제 할 때 --recursive
git이 루트 저장소와 모든 하위 모듈을 자동으로 복제하도록 하는 옵션 만 추가하면 됩니다.
git clone --recursive my_sub_project_git_url
도움이되기를 바랍니다.
나는 gradle이 git repo를 의존성으로 추가하는 것을 지원한다고 생각하지 않습니다. 내 해결 방법은 다음과 같습니다.
- 메인 프로젝트가 파일 시스템의 다른 프로젝트에 의존한다고 선언
- 종속성으로 선언 된 폴더에서 git repo를 자동으로 복제하는 방법을 제공합니다.
메인 프로젝트 리포지토리의 폴더 외부에 라이브러리 리포지토리를 원한다고 가정하므로 각 프로젝트는 독립적 인 git 리포지토리가되고 라이브러리 및 메인 프로젝트 git 리포지토리에 독립적으로 커밋 할 수 있습니다.
라이브러리 프로젝트의 폴더를 메인 프로젝트의 폴더와 같은 폴더에두고 싶다고 가정하면,
다음과 같이 할 수 있습니다.
최상위 settings.gradle에서 라이브러리 저장소를 파일 시스템의 위치에 따라 프로젝트로 선언합니다.
// Reference: https://looksok.wordpress.com/2014/07/12/compile-gradle-project-with-another-project-as-a-dependency/
include ':lib_project'
project( ':lib_project' ).projectDir = new File(settingsDir, '../library' )
gradle-git 플러그인 을 사용하여 git 저장소에서 라이브러리를 복제합니다.
import org.ajoberstar.gradle.git.tasks.*
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.ajoberstar:gradle-git:0.2.3' }
}
task cloneLibraryGitRepo(type: GitClone) {
def destination = file("../library")
uri = "https://github.com/blabla/library.git"
destinationPath = destination
bare = false
enabled = !destination.exists() //to clone only once
}
In the dependencies of your project, say that the code of your project depends on the folder of the git project
dependencies {
compile project(':lib_project')
}
The closest thing I have found is https://github.com/bat-cha/gradle-plugin-git-dependencies but I can't get it to work with the android plugin, keeps trying to pull from maven even after the git repos are loaded.
There is now a new feature in gradle that lets you add source dependencies from git.
You first need to define the repo in the settings.gradle
file and map it to a module identifier:
sourceControl {
gitRepository("https://github.com/gradle/native-samples-cpp-library.git") {
producesModule("org.gradle.cpp-samples:utilities")
}
}
And now in your build.gradle
you can point to a specific tag (e.g.: 'v1.0'):
dependencies {
...
implementation 'org.gradle.cpp-samples:utilities:v1.0'
}
Or to a specific branch:
dependencies {
...
implementation('org.gradle.cpp-samples:utilities') {
version {
branch = 'release'
}
}
}
Caveats:
- Gradle 4.10 or higher required
- Does not support authentication yet
References:
'development' 카테고리의 다른 글
ASP.NET MVC 상대 경로 (0) | 2020.08.23 |
---|---|
json.org에서 사용되는 철도 다이어그램 생성 도구 (0) | 2020.08.23 |
JavaScript에 대한 브라우저 통계 비활성화 됨 (0) | 2020.08.23 |
하나의 C 소스 파일을 다른 파일에 포함 하시겠습니까? (0) | 2020.08.23 |
Android에서 캔버스를 통해 빈 비트 맵 생성 및 그리기 (0) | 2020.08.23 |