如何在Gradle中定义一个编译时* only *类路径? [英] How do I define a compile-time *only* classpath in Gradle?

查看:233
本文介绍了如何在Gradle中定义一个编译时* only *类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我一个简单的build.gradle例子,如何指定不包括在运行时部署(war)中的仅编译时类。

Can someone please give me a simple build.gradle example of how I can specify compile-time-only classes that are not included in the runtime deployment (war).

Gradle似乎得到了错误的方式,因为'runtime'继承自'compile'。我不能想象一种情况,我想在运行时,我不想在编译时的类。然而,在许多情况下,我需要类在编译时生成代码,我不希望在运行时部署!

Gradle seems to have gotten this the wrong way around since 'runtime' inherits from 'compile'. I can't imagine a situation where I would want classes at runtime that I wouldn't want at compile time. However, there are many circumstances where I need classes to generate code at compile time that I do not wish to deploy at runtime!

我已经通过the肿的gradle文档,但没有找到任何明确的说明或示例。我怀疑这可能通过定义一个配置,并将其设置为CompileJava插件的类路径实现 - 但文档没有解释如何实现这一点。

I've ploughed through the bloated gradle documentation but cannot find any clear instructions or examples. I suspect this might be achieved by defining a 'configuration' and setting it as the classpath of the CompileJava plugin - but the documentation falls short on explaining how to achieve this.

推荐答案

已经有很多关于这个主题的讨论,主要是这里,但没有明确的结论。

There has been a lot of discussion regarding this topic, mainly here, but not clear conclusion.

你是在正确的轨道:目前最好的解决方案是声明你的自己提供配置,这将包括只编译依赖项并添加到您的编译类路径:

You are on the right track: currently the best solution is to declare your own provided configuration, that will included compile-only dependencies and add to to your compile classpath:

configurations{
  provided
}

dependencies{
  //Add libraries like lombok, findbugs etc
  provided '...'
}

//Include provided for compilation
sourceSets.main.compileClasspath += [configurations.provided]

// optional: if using 'idea' plugin
idea {
  module{
    scopes.PROVIDED.plus += [configurations.provided]
  }
}

// optional: if using 'eclipse' plugin
eclipse {
  classpath {
    plusConfigurations += [configurations.provided]
  }
}

通常情况下效果不错。

这篇关于如何在Gradle中定义一个编译时* only *类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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