Gradle提供了Intellij的依赖关系 [英] Gradle provided dependencies with Intellij

查看:605
本文介绍了Gradle提供了Intellij的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个Bukkit插件。该插件还使用 exp4j 最终结果需要包含在发布的jar中的exp4j代码,但 没有包含Bukkit代码。 b
$ b

我遵循此答案的建议复制依赖关系并使用此答案按照规定声明Bukkit。我的build.gradle现在看起来像这样:

  apply plugin:'java'
apply plugin:'idea'

配置{
提供
}

sourceSets {
main.compileClasspath + =配置。提供
test.compileClasspath + = configurations.provided
test.runtimeClasspath + = configurations.provided
}

dependencies {
providedorg.bukkit:bukkit:1.8.8-R0.1- SNAPSHOT
compilenet.objecthunter:exp4j:0.4.5
}

jar {
//将
从$ { b $ b configurations.compile.collect {
it.isDirectory()?它:zipTree(它)
}
}
}

这很好,我可以使用Gradle从命令行快速构建和运行项目。麻烦的是,Intellij(或者也许是Gradle的想法插件)不能识别提供的依赖关系,因此,从Bukkit导入任何东西都会导致它错误地报告错误。



我怎样才能让提供的依赖与想法一致?



我试过的其他东西:



我也试过声明这样提供的范围:

 配置{
提供
编译。 extends从提供的
}

但是这会导致提供的依赖被复制到最终的jar中。我也尝试了这个答案所推荐的插件,但都导致Bukkit被复制到创建的jar中。我进一步尝试将Bukkit声明为运行时作用域,但这只是导致了很多编译错误(但有趣的是,Intellij确实将Bukkit列为依赖项)



I难以相信之前没有问过这个问题,但是我搜索了并找不到完整的解决方案。我是新来的Gradle,非常抱歉,如果这是一件非常简单的事情。

Gradle issue here。



没有在gradle中提供了配置,但实际上应该有一个。目前看来最合理的解决方法是创建自己的配置:

 配置{
提供
}

然后:

  sourceSets {
main {
compileClasspath + = configurations.provided
}
}
$ b $ extendsFrom 的问题在于,提供的依赖关系最终会被捆绑到您的分配中,除非您添加另一个显式排除,击败提供的整个点。编辑:为了告诉想法使用提供的依赖关系,您可以应用'idea' / code>插件然后:

  idea {
module {
scopes.PROVIDED。 plus + = [configurations.provided]
}
}

请参阅 more here。


I'm trying to build a Bukkit plugin. The plugin also uses exp4j. The final result needs to have the exp4j code included in the released jar but not have the Bukkit code included.

I followed the advice of this answer to copy the dependencies in and used this answer to declare Bukkit as provided. My build.gradle now looks like this:

apply plugin: 'java'
apply plugin: 'idea'

configurations {
    provided
}

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}

dependencies {
    provided "org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT"
    compile "net.objecthunter:exp4j:0.4.5"
}

jar {
    // copy the dependencies across
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
}

This works great and I can build and run the project happily using Gradle from the command line. The trouble is that Intellij (or maybe it's the Gradle idea plugin) doesn't recognise the provided dependencies, thus, importing anything from Bukkit causes it to incorrectly report an error.

How can I get the provided dependencies to play nicely with idea?

Other things I've tried:

I've also tried declaring the provided scope like this:

configurations {
    provided
    compile.extendsFrom provided
}

But this causes the provided dependencies to be copied into the final jar. I've also tried the plugins as recommended by this answer, but both cause Bukkit to be copied into the created jar. I've further tried declaring Bukkit to be runtime scope instead provided, but that simply caused lots of compile errors (but interestingly Intellij did have Bukkit listed as a dependency)

I have trouble believing that this has not been asked before, but I've searched and cannot find a full solution. I'm new to Gradle, so apologies if this is a super simple thing to do.

解决方案

See Gradle issue here.

There isn't a provided configuration in gradle, though there really should be one. The most reasonable workaround currently seems to be, to create your own configuration:

configurations {
    provided
}

and then:

sourceSets {
    main {
      compileClasspath += configurations.provided
    }
}

The problem with extendsFrom is that the provided dependency will end up being bundled in your distribution anyway unless if you add another explicit exclude, defeating the whole point of provided.

Edit: To tell idea to use the provided dependencies, you could apply the 'idea' plugin and then:

idea {
  module {
    scopes.PROVIDED.plus += [ configurations.provided ]
  }
}

see more here.

这篇关于Gradle提供了Intellij的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆