Intellij Idea 如何添加打包在zip中的依赖项

klh5stk1  于 2023-10-15  发布在  其他
关注(0)|答案(2)|浏览(116)

我找不到在gradle中你应该如何依赖一个打包在zip依赖项中的jar。我的用例是从intellij的分发存储库中检索platform-api.jar工件。

jdgnovmf

jdgnovmf1#

到处都找遍了,但找不到答案。通过使用分布的分离配置的zipTree来巧妙地解决它,如下所示:

...
dependencies {
    ...
    implementation zipTree(project.configurations.detachedConfiguration(dependencies.create("com.jetbrains.intellij.idea:ideaIC:2021.1.2")).singleFile).matching {
        include "lib/platform-api.jar"
    }
}
daolsyd0

daolsyd02#

如果你想避免每次构建运行时都解压缩,你可以使用一个任务并利用最新的检查(参见authoring tasks和通过运行时API声明任务输入和输出)

configurations {
   intellij
}
dependencies {
   intellij 'com.jetbrains.intellij.idea:ideaIC:2021.1.2'
   implementation tasks.named('intellijUnzip')
}
tasks.register('intellijUnzip') {
   inputs.files configurations.intellij
   outputs.dir "$buildDir/intellijUnzip"
   doLast {
      copy {
         from zipTree(configurations.intellij.singleFile)
         include "lib/platform-api.jar"
         into "$buildDir/intellijUnzip"
      } 
   }
}

相关问题