【问题标题】:the stuff of "compile project" can't be carried into the aar when publish to maven reporsitory发布到 maven 存储库时无法将“编译项目”的内容带入 aar
【发布时间】:2016-12-22 03:58:00
【问题描述】:

当我使用依赖项 compile 'cn.dreamtobe.android.phone:sdkproject-library:1.0.1 编译 DemoProject:demo 时,它失败并出现以下错误提示:

Download http://mymaven.dreamtobe.cn:8081/artifactory/content/repositories/mobile/cn/dreamtobe/android/phone/sdkproject-library/1.0.0/sdkproject-library-1.0.1.pom

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':demo'.
> Could not resolve all dependencies for configuration ':demo:_debugCompile'.
   > Could not find SDKProject:api:unspecified.
     Searched in the following locations:
         file:/Users/Jacksgong/.m2/repository/SDKProject/api/unspecified/api-unspecified.pom
         file:/Users/Jacksgong/.m2/repository/SDKProject/api/unspecified/api-unspecified.jar
         https://jcenter.bintray.com/SDKProject/api/unspecified/api-unspecified.pom
         https://jcenter.bintray.com/SDKProject/api/unspecified/api-unspecified.jar
     Required by:
         DemoProject:demo:unspecified > cn.dreamtobe.android.phone:sdkproject-library:1.0.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 42.323 secs

所以真正的问题是:

在将:libray 模块发布到maven repo 时,如何将:api 模块的内容放在一起,而不是仅仅在.pom 文件中声明。

由于在DemoProject中找不到,因为':api'只能在SDKProject中识别

我的 SDKProject 层次结构是:

SDKProject
|- library module(`:library`)
|- api module(`:api`)

library-module 依赖于 api-module,下面是 library-module 中的build.gradle

...
dependencies {
  compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  compile project(':api')
}

ext {
  GROUP_ID = GROUP
  POM_ARTIFACT_ID = IMPL_POM_ARTIFACT
}

apply from: '../upload.gradle'

SDKProject根目录下的upload.gradle脚本:

  apply plugin: 'maven'

  ext {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    MVN_NAME = properties.getProperty("mvn.dev.user")
    MVN_PASSWORD = properties.getProperty("mvn.dev.password")
  }

  afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                pom.groupId = GROUP_ID
                pom.artifactId = POM_ARTIFACT_ID
                pom.version = VERSION_NAME

                repository(url: RELEASE_REPOSITORY_URL) {
                  authentication(userName: MVN_NAME, password: MVN_PASSWORD)
                }

                snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
                  authentication(userName: MVN_NAME, password: MVN_PASSWORD)
                }
              }
          }
    }
    task sourcesJar(type: Jar) {
      from android.sourceSets.main.java.srcDirs
      classifier = 'sources'
    }

    task javadoc(type: Javadoc) {
      failOnError false
      source = android.sourceSets.main.java.srcDirs
      options {
          charSet = 'UTF-8'
          links "http://docs.oracle.com/javase/7/docs/api/"
          linksOffline "http://d.android.com/reference", System.getenv("ANDROID_HOME") + "/docs/reference"
      }
      classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
      classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
      classifier = 'javadoc'
      from javadoc.destinationDir
    }

    artifacts {
      archives javadocJar
      archives sourcesJar
    }
  }

【问题讨论】:

    标签: java maven gradle android-gradle-plugin


    【解决方案1】:

    我通过flat-aar自己解决了这个问题。

    另外一种方式是将Apis代码和Impls代码放在同一个模块中,写gradle |ike this :publishing multiple modules to maven,这样gradle脚本就会把Api和Impl作为两个模块过滤掉。

    终于

    我为此问题创建了两个示例演示:https://github.com/Jacksgong/gralde-sample

    【讨论】:

      猜你喜欢
      • 2015-05-20
      • 2020-12-11
      • 2013-12-06
      • 2019-12-27
      • 2020-12-04
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多