相关疑难解决方法(0)

如何在Gradle中定义编译时*仅*类路径?

有人可以给我一个简单的build.gradle示例,说明如何指定未包含在运行时部署(war)中的仅编译时类.

由于'运行时'继承自'compile',Gradle似乎已经采用了错误的方法.我无法想象在运行时我想要在编译时不想要的类的情况.但是,在很多情况下我需要类在编译时生成代码,我不希望在运行时部署它们!

我已经浏览了膨胀的gradle文档,但找不到任何明确的说明或示例.我怀疑这可能是通过定义'配置'并将其设置为CompileJava插件的类路径来实现的 - 但是文档不能解释如何实现这一点.

compilation classpath gradle

62
推荐指数
6
解决办法
3万
查看次数

Gradle:如何在包装中排除编译范围文件依赖关系?

我有一个多模块gradle项目,具有以下基本结构:

root
  core
  c-interface
  m-interface
Run Code Online (Sandbox Code Playgroud)

c接口和m接口都依赖于核心项目:

compile project(':root:core')
Run Code Online (Sandbox Code Playgroud)

c-interface和m-interface使用WAR插件,但核心没有,只是一个jar.

在核心项目中,我将通过以下方式提取一些文件系统依赖项.其中一个依赖项我不能打包在由c-interface和m-interface生成的WAR中.以前我在nexus maven存储库中有这种依赖关系,所以我可以在c-interface和m-interface中的providedRuntime配置中按组,名称,版本排除它.

我无法弄清楚如何对文件依赖性做同样的事情.gradle依赖项任务不列出文件依赖项,因此我不知道我将在provideRuntime中放入什么.

我阅读了http://issues.gradle.org/browse/GRADLE-471但是尝试使用这个想法似乎没有从我的包中删除存档.这是我目前正在定义的内容(在核心的build.gradle中):

compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compile(files('dependencies/compile/archive/management.jar')){ notPackaged = true  } // Excludes it from all publications
Run Code Online (Sandbox Code Playgroud)

更新

提供没有war插件的编译看起来像是一种可能性.我在核心build.gradle中设置它并且编译得很好,但是c-interface和m-interface在编译时也需要依赖.在c-interface和m-interface中包含作为providedCompile(甚至是带有compile的健全性检查)的文件并没有修复与缺少management.jar依赖关系相关的编译时错误.我的推测是因为它已经作为核心中的compile作用,以便在c-interface和m-interface中忽略新的声明.

核心/的build.gradle:

configurations { providedCompile }

dependencies {
    providedCompile files('dependencies/compile/archive/management.jar')
}

sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile
Run Code Online (Sandbox Code Playgroud)

C-接口/的build.gradle:

providedCompile files('dependencies/compile/archive/management.jar')
Run Code Online (Sandbox Code Playgroud)

dependencies build gradle

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

gradle ×2

build ×1

classpath ×1

compilation ×1

dependencies ×1