여러 프로젝트에서 재사용할 수 있는 코드들을 매번 복붙하지 않고 하나의 모듈로 분리한 후 의존성으로 불러와서 사용할 수 있으면 나중에 수정도 쉽고 용이할 것이다.
이를 라이브러리라고 부르는데 모든 라이브러리가 다 오픈소스인 건 아니니까 라이센스를 잘 확인하고 사용하자
빈 프로젝트를 생성한 후 내가 라이브러리화 할 코드가 담근 모듈을 생성하자

라이브러리로 배포하기 위해 필요한 정보를 설정하자
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("maven-publish")
}
"maven-publish"를 추가하여서 maven을 통해 빌드가 가능하도록 하자
그리고 dependencies 밑에
afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
// You can then customize attributes of the publication as shown below.
groupId = "com.github.uuranus"
artifactId = "animated-dialog-compose"
version = "1.0.0"
}
// Creates a Maven publication called “debug”.
create<MavenPublication>("debug") {
// Applies the component for the debug build variant.
from(components["debug"])
groupId = "com.github.uuranus"
artifactId = "animated-dialog-compose"
version = "1.0.0"
}
}
}
}





한 번에 성공적으로 배포가 되면 좋겠지만^^ 이렇게 빨간색 문서가 뜨면 문제가 생겨 배포에 실패했다는 의미이다. 빨간 문서를 클릭하여서 어디서 문제가 되었는지 확인해보자.
* What went wrong:
A problem occurred configuring root project 'animated-compose-dialog'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:8.3.1.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:8.3.1
project : > com.android.library:com.android.library.gradle.plugin:8.3.1
> No matching variant of com.android.tools.build:gradle:8.3.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.4' but:
- Variant 'apiElements' capability com.android.tools.build:gradle:8.3.1 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
//...

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
하지만 다시 배포해도 자바 버전 오류는 사라지지 않았다.
Build time: 2023-10-04 20:52:13 UTC
Revision: e9251e572c9bd1d01e503a0dfdf43aedaeecdc3f
Kotlin: 1.9.10
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 1.8.0_292 (Private Build 25.292-b10)
OS: Linux 4.18.0-13-generic amd64
0m2.988s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
Getting tasks: ./gradlew tasks --all
Tasks:
나는 자바 버전을 17로 올려줬는데 왜 아직도 1.8 버전으로 빌드를 하고 있지???
JitPack에서 빌드를 할 때 프로젝트의 자바 버전에 맞춰서 빌드를 하는 게 아니고 자체 jdk로 빌드를 하는 것 같다.
그럼 JitPack의 자바 버전을 어떻게 바꾸지????
jdk:
- openjdk17
야호! 이제 내가 만든 코드를 다른 프로젝트에서 사용할 수 있다.
https://android-developer.tistory.com/11
https://rkdxowhd98.tistory.com/199