我只是从eclipse改为android studio。为了获得好处,gradle教我们,我正在尝试使用jForgs Artifacts建立一个本地存储库。现在我面临的问题是,我想将我在Android Studio中编写的库推送/发布到工件中,这样我就可以通过我的下一个Android App项目中的依赖项轻松导入它。
文件夹结构如下所示:
LibDeploy
build.gradle
gradle.properties
-> app
--> build
--> libs
--> src
--> main
--> java
build.gradle
-> gradle
--> wrapper
我在app文件夹中的gradle.build看起来像这样:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0'
classpath 'com.github.dcendents:android-maven-plugin:1.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.3'
}
}
import java.text.SimpleDateFormat
def globalVersion = new Version(currentVersion)
// Define the artifacts coordinates
group = 'org.jfrog.example.android'
version = globalVersion
status = version.status
// Plugins
apply plugin: 'com.android.library'
apply plugin: 'artifactory'
// We need the patched maven plugin since 'install' task is overriden by 'installDebugTest', see: https://github.com/dcendents/android-maven-plugin
apply plugin: 'android-maven'
// Android
android {
compileSdkVersion 21
buildToolsVersion "21.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
}
configurations {
published
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java
classifier "sources"
}
artifactoryPublish {
dependsOn sourceJar
}
artifacts {
published sourceJar
}
configure(install.repositories.mavenInstaller) {
pom.project {
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}
artifactory {
contextUrl = 'http://localhost:8080/artifactory'
publish {
repository {
repoKey = 'libs-snapshot-local' //The Artifactory repository key to publish to
username = artifactory_user //The publisher user name, property taken from gradle.properties
password = artifactory_password //The publisher password, property taken from gradle.properties
}
defaults {
publishConfigs('archives', 'published')
properties = ['build.status': "$it.project.status".toString()]
publishPom = true //Publish generated POM files to Artifactory (true by default)
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
resolve {
repository {
repoKey = 'libs-release' //The Artifactory (preferably virtual) repository key to resolve from
username = artifactory_user //Optional resolver user name (leave out to use anonymous resolution), property taken from gradle.properties
password = artifactory_password //The resolver password, property taken from gradle.properties
}
}
}
repositories {
jcenter()
}
// Our project dependencies
dependencies {
compile 'joda-time:joda-time:2.3'
// Backward compatibility for andoird <http://developer.android.com/tools/support-library/index.html>
//compile 'com.android.support:support-v4:19.1.+'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
class Version {
String thisVersion = 'default'
String status = 'default'
Version(String versionValue) {
thisVersion = versionValue
if (thisVersion.endsWith('-SNAPSHOT')) {
status = 'integration'
} else {
status = 'release'
}
}
String toString() {
thisVersion
}
}
当我尝试通过gradlew artifactoryPublish
推送/发布到工件时
我收到了错误:
:app:sourceJar
FAILURE: Build failed with an exception.
* What went wrong:
Cannot convert the provided notation to a File or URI: [src/main/java].
The following types/formats are supported:
- A String or CharSequence path, e.g 'src/main/java' or '/usr/include'
- A String or CharSequence URI, e.g 'file:/usr/include'
- A File instance.
- A URI or URL instance.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
我认为问题应该出现在build.gradle文件的这一行
中task sourceJar(type: Jar) {
from android.sourceSets.main.java
classifier "sources"
}
有没有人如何为我们的构建过程设置中央maven仓库? 提前谢谢!
答案 0 :(得分:2)
我通过改变
解决了这个问题task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main
}
到
task sourcesJar(type: Jar) {
classifier = 'sources'
from 'src/main/java'
}