![](/img/trans.png)
[英]Maven project with JAXB2 plugin does not work without maven clean
[英]Gradle Maven plugin "install" task does not work with Android library project
我想將 android 庫項目安裝到本地 maven 存儲庫。 這是build.gradle :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
version = "1.0.0-SNAPSHOT"
group = "com.example"
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
}
當我運行時:
gradle install -i
它卡在這里:
Executing task ':project:installTest' due to:
Task has not declared any outputs.
Starting process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''. Working directory: D:\Projects\java\....... Command: d:\android-sdk-windows\platform-tools\adb.exe install -r D:\Projects\java\.......\build\apk\project.apk
An attempt to initialize for well behaving parent process finished.
Successfully started process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''
> Building > :project:installTest
所以我注意到的第一件事是它出於某種奇怪的原因試圖將它作為 APK 部署在設備上。
我做錯了什么還是只是android-library插件與maven插件不兼容?
編輯:請參閱 github 頁面 ( https://github.com/dcendents/android-maven-gradle-plugin ) 以獲取最新說明並找到要使用的正確版本。 原始說明不再適用於最新的 gradle 版本。
原帖:
我已經修改了 maven 插件以與 android 庫項目兼容。 項目見github: https : //github.com/dcendents/android-maven-gradle-plugin
配置您的 android 庫項目以使用它:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
apply plugin: 'android-library'
apply plugin: 'android-maven'
然后您應該能夠使用安裝任務將 aar 安裝到您的本地 Maven 存儲庫中。
希望這會有所幫助,如果您發現插件有問題,請在 github 上告訴我,我會修復它。
詳細闡述 CyclingSir 的回答,我建議添加一個單獨的“installArchives”任務。 這也應該照顧到您的自定義工件(例如源)。
apply plugin: 'maven'
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
configuration = configurations['archives']
repositories {
mavenDeployer {
repository url: repositories.mavenLocal().url
}
}
}
請注意,使用 Gradle Android 插件 v0.5.5, gradle install
仍會嘗試在設備上安裝某些內容。
如果您不想使用自定義插件,有一個更簡單的解決方案。 相反,只需使用不同的名稱重新創建安裝任務。 我稱之為installArchives
。 將以下代碼添加到您的build.gradle
:
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
repositories.mavenInstaller {
configuration = configurations.default
pom.groupId = 'my.group'
pom.artifactId = 'my-artifact'
pom.version = '1.0.0'
}
}
您現在可以運行gradle installArchives
在本地安裝您的 aar。
更新 2014-11-26
在撰寫本文時,當 Android 構建工具的版本為 0.5.5 時,下面的答案是有意義的。 它現在很可能已經過時,並且可能不再起作用。
我個人已將我的項目切換為使用android-maven-plugin
,如上述答案中所述,該插件也適用於最新版本的 Android Build Tools。
2014 年 2 月的原始答案
作為 AAR 發布
如果你不介意使用的舊版本com.android.tools.build:gradle
(即0.5.4),你可以使用的方法中說明此博文。 並不是說根據adt-dev mailing-list 中的討論,這在 0.5.5 中不起作用。
build.gradle
添加到您的build.gradle
:
apply plugin: 'maven-publish'
// load bundleRelease task
// this will not load the task in 0.5.5
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
要發布到您的本地 Maven 存儲庫,請調用以下命令:
gradle publishToMavenLocal
發布為 JAR
如果您的 Android 庫沒有自定義資源並且可以作為 JAR 發布,那么您可以使用以下build.gradle
,即使在 0.5.5 中也可以使用。
// build JAR file
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/classes/release/"
}
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact androidReleaseJar
}
}
}
要發布到您的本地 Maven 存儲庫,請調用以下命令:
gradle publishToMavenLocal
我剛剛通過定義上傳檔案解決了這個問題,如下所述: Gradle 文檔 52.6.2。 部署到 Maven 存儲庫
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
打電話
gradle uploadArchives
將人工制品部署到(在我的情況下是本地)Maven 存儲庫。 我還沒有找到一種簡單且更靈活的方法來指定本地 repo 的 url,例如 mavenLocal() ,但上述方法適合我的需要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.