简体   繁体   English

在Eclipse中声明编译和运行时之间的瞬时依赖关系的最佳方法是什么?

[英]What is the best way to declare transient dependencies between compile and runtime with Eclipse?

We are looking to revamp our Java build process on Eclipse. 我们正在寻求在Eclipse上改进Java构建过程。 Currently we use Gradle! 目前,我们使用Gradle! As a part of that effort we are looking at whether we are using Gradle in the best possible way. 作为这项工作的一部分,我们正在研究是否正在以最佳方式使用Gradle。 We use the Eclipse plugin for Gradle and declare our dependencies with compile. 我们将Eclipse插件用于Gradle,并使用compile声明我们的依赖项。 Unfortunately this adds a ton of transient dependencies with our generated Eclipse projects which is not desirable. 不幸的是,这给我们生成的Eclipse项目增加了大量的临时依赖关系,这是不希望的。 These extra dependencies are only valid at runtime. 这些额外的依赖项仅在运行时有效。

So, is there a way to declare a dependency ONCE in Gradle and have its compile dependency set to the first level of dependency and its runtime dependency set to the first level plus transient dependencies? 那么,是否有一种方法可以在Gradle中声明依赖项ONCE,并将其编译依赖项设置为第一级依赖项,并将其运行时依赖项设置为第一级并加上瞬态依赖项?

Currently we use the @jar syntax with compile which gives us the first level dependency for compile, but we still have to declare that dependency again for runtime. 当前,我们将@jar语法与compile一起使用,这为我们提供了用于编译的第一级依赖关系,但对于运行时,我们仍然必须再次声明该依赖关系。 Not ideal because we have two places to go in order to update a dependency. 这并不理想,因为我们有两个地方可以更新依赖项。

Is there a better way? 有没有更好的办法?

I assume you mean transitive dependencies. 我假设您的意思是传递依赖。

If you only want direct dependencies to appear on Gradle's compile class path, your current solution seems reasonable. 如果只希望直接依赖项出现在Gradle的编译类路径中,则当前的解决方案似乎很合理。 (In the future we want to have a more accurate compile class path out-of-the-box.) Potential improvements are to make the compile configuration non-transitive (rather than using @jar ) or to write a plugin that provides a custom dependency syntax, thereby making the duplication between compile and runtime dependencies go away. (将来,我们希望开箱即@jar提供更准确的编译类路径。)潜在的改进是使compile配置不具有传递性(而不是使用@jar )或编写一个提供自定义功能的插件依赖语法,从而消除了编译依赖和运行时依赖之间的重复。

However, this won't help you with Eclipse, as Eclipse has no notion of separate compile and runtime class paths. 但是,这对Eclipse没有帮助,因为Eclipse没有单独的编译和运行时类路径的概念。 The only way out is to make run configurations responsible for providing the runtime class path, but this might be difficult to set up (eg run configurations are often created on-the-fly), and Gradle doesn't have any out-of-the-box support for this. 唯一的出路是让运行配置负责提供运行时类路径,但这可能很难设置(例如,运行配置通常是即时创建的),并且Gradle不会有任何过时的对此的支持。 You could use the generic XML hooks of Gradle's Eclipse plugin to generate run configurations, but I'm not sure if the Eclipse Gradle integration would pick them up. 您可以使用Gradle的Eclipse插件的通用XML挂钩来生成运行配置,但是我不确定Eclipse Gradle集成是否可以使用它们。

Due to these difficulties, most Eclipse developers put all runtime dependencies on the Eclipse project class path (regardless of whether they are using Gradle or not), despite the obvious disadvantages. 由于这些困难,尽管有明显的缺点,但是大多数Eclipse开发人员都将所有运行时依赖项放在Eclipse项目类路径上(无论他们是否使用Gradle)。

Our vision is that Gradle can one day act as the build engine for Eclipse. 我们的愿景是Gradle有一天可以充当Eclipse的构建引擎。 Once this happens, discrepancies between IDE and build tool (class paths, code generation, integration testing, etc.) will be a thing of the past. 一旦发生这种情况,IDE和构建工具之间的差异(类路径,代码生成,集成测试等)将成为过去。 Gradle can already act as the build engine for NetBeans today, and soon also for IntelliJ IDEA (driven by the requirements for Android Studio). Gradle现在已经可以充当NetBeans的构建引擎,并且很快也可以充当IntelliJ IDEA(由Android Studio的要求驱动)。

While I certainly agree with @Peter that an overhaul of the Eclipse build process is a long-term goal, in the short term you may be able to accomplish what you want using Maven and m2eclipse. 我当然同意@Peter的观点,即对Eclipse构建过程进行全面检查是一个长期目标,但在短期内,您可以使用Maven和m2eclipse完成您想要的工作。 Whether the tradeoffs of moving to Maven are worth that extra control are entirely up to you. 迁移到Maven的权衡是否值得额外控制完全取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM