2

我编写了以下任务,它为我的每个子项目提取所有编译依赖项并将它们放在每个子项目目录中:

task exportCompileLibs << {
  subprojects.each { iSubProject ->
    iSubProject.configurations.findAll{it.name == "compile"}.each{ jConfig ->
      println "copying compile libs for ${iSubProject.name}..."
      copy {
        into "${iSubProject.buildDir}/gradle-lib-export"
        from jConfig
        eachFile {println it.name}
      }
    }
  }
}

我想扩展它以导出 Gradle 已经知道的源工件(我可以在缓存目录中看到源 jar),我只是不知道如何使用对象模型来处理他们。

IDEA 和 Eclipse 插件似乎能够做到这一点(他们将他们构建的项目文件直接指向 gradle 缓存),但我无法弄清楚如何做到这一点 - 并且查看 IDE 插件源代码,它看起来......棘手。我希望 gradle DSL 或 API 中缺少一些明显的东西。

有人有什么想法吗?

4

2 回答 2

1

对于任何寻求至少临时解决方案的人来说,以下似乎正在做我目前想要的。

对于要导出依赖项的每个项目,您必须将 IDEA 插件应用于 build.gradle 文件:

应用插件:“想法”

然后定义这个任务:

task exportDependencies << {
  def deps = project.extensions.getByType(IdeaModel).module.resolveDependencies()
  copy {
    from deps*.classes.file
    into "${buildDir}/gradle-lib-export/libs"
  }

  copy {
    from deps*.sources.file
    into "${buildDir}/gradle-lib-export/sources"
  }
}

这是我可怕的 hack,所以我不必为每个子项目应用插件:

task exportDependencies(description: "export project dependency jars") << {
  subprojects.each { Project iSubProject ->
    String target = "${iSubProject.buildDir}/gradle-lib-export"

    IdeaPlugin ideaPlugin = new IdeaPlugin()
    ideaPlugin.apply(iSubProject)
    Set<Dependency> deps = ideaPlugin.model.module.resolveDependencies()

    println "exporting dependencies for $iSubProject.name into $target"
    copy {
      from deps*.classes.file
      into "${target}/libs"
      eachFile { println "lib -> $it.name" }
    }
    copy {
      from deps*.sources.file
      into "${target}/sources"
      eachFile{ println "source -> $it.name" }
    }
  }
}

+10 分,因为我的构建任务列表中没有我不想要的东西,- 几百万分 ewwwww

于 2012-09-11T11:50:43.103 回答
0

目前没有比 IDE 插件更简单的方法了。这有望在未来有所改变。

于 2012-09-09T12:20:31.997 回答