简体   繁体   English

我应该使用Eclipse插件(或OSGi捆绑软件)作为普通的依赖项管理工具吗?

[英]Should I use Eclipse plug-ins (or OSGi Bundles) as a plain dependency management tool?

once again it has happened... I joined a new project, composed of several plain Eclipse Java Projects, with interdependencies, all managed through the Project build path. 再次发生了……我加入了一个新项目,该项目由几个相互依赖的简单Eclipse Java项目组成,所有项目都通过项目构建路径进行管理。 I find this all a bit of a chaos. 我觉得这有点混乱。 And when it comes to run configurations - you just enter hell. 当涉及到运行配置时,您只需输入地狱即可。

In the past I've sticked to create plug-in projects, instead of plain Java projects - even if I never intend to run these projects as osgi-bundles. 过去,即使我从未打算将这些项目作为osgi-bundles运行,我仍然坚持创建插件项目,而不是普通的Java项目。 I just find that dependencies are way easier to manage in plug-in projects. 我只是发现依赖关系在插件项目中更易于管理。 Are other people taking the same path? 其他人走同样的路吗? Anything against this approach? 反对这种方法吗?

If you read the restructure of org.aspectj document , that project did precisely that: 如果您阅读org.aspectj文档重组,那么该项目正是这样做的:

  • All dependencies would be expressed in OSGi bundle manifest files, which specify a classpath (for library jars) and "required" bundles. 所有依赖项都将在OSGi捆绑包清单文件中表示,该文件指定一个类路径(用于库jar)和“必需”捆绑包。
    Libraries expected or hoped for in the deployment environment (eg, XML or JRocket ) must be included for build and test purposes but excluded from the shipping product. 出于构建和测试目的,必须包括部署环境中预期或希望的库(例如XMLJRocket ),但不应包括在发货产品中。 These might be specified as "optional" required-bundles or as required-packages 这些可能被指定为“可选”必需包或必需包

  • Initial binary assembly would work through the usual bundle assembly, with the bundle output including binaries from bundle fragments it requires (but not from optional bundles) 初始二进制程序集将通过通常的bundle程序集工作,bundle输出包括其所需的bundle片段中的二进制文件(但不包括可选的bundle中的二进制文件)

The benefits also include the version aspect of OSGi, which allows to specify the minimum and maximum expected version of a dependency. 好处还包括OSGi的版本方面,它允许指定依赖项的最小和最大预期版本。

I agree that in Eclipse it is easier to manage project dependencies using OSGi than the traditional way of adding project or library references. 我同意,在Eclipse中,使用OSGi管理项目依赖关系比添加项目或库引用的传统方式要容易得多。

However, if you promote the OSGi-way of dependency management at development time, developers will need to learn OSGi and there will be a cost as they get class visibility issues. 但是,如果在开发时推广OSGi-依赖性管理方式,则开发人员将需要学习OSGi,并且由于遇到类可见性问题而将付出一定的代价。

Are you using Require-Bundle or Import-Package for managing the dependencies? 您是否正在使用Require-BundleImport-Package来管理依赖项? Even though Require-Bundle is not the recommended choice with OSGi, it might be a better fit from the point-of-view of development-time dependency management. 即使Require-Bundle不是OSGi的推荐选择,但从开发时间依赖性管理的角度来看,它可能更适合。

Unless you are using something like the Maven plug-in, Eclipse has the annoying split of completely different methods of compiling/running inside Eclipse and outside - with the pain of maintaining 2 parallel compile/run systems. 除非您使用Maven插件之类的东西,否则Eclipse将在Eclipse内部和外部进行完全不同的编译/运行方法的烦人分裂-维护2个并行编译/运行系统很麻烦。

I think your methodology, to use OSGi for dependency management even if you will not be running inside an OSGi container, is very sound because ultimately it will lead to more modular code. 我认为,即使您不在OSGi容器中运行,也要使用OSGi进行依赖项管理的方法非常合理,因为最终它将导致更多的模块化代码。 Modular code is easier to refactor and easier to distribute among multiple developers. 模块化代码更易于重构,更易于在多个开发人员之间分发。 You don't even need to extend any OSGi classes, so you don't create any additional dependencies. 您甚至不需要扩展任何OSGi类,因此无需创建任何其他依赖项。

On the other hand, Ken Liu's suggestion of using an external dependency management has it's advantages too, since something like Maven will handle a lot of the dependency and management for you. 另一方面,Ken Liu提出的使用外部依赖项管理的建议也具有其优势,因为Maven之类的东西将为您处理很多依赖项和管理。

Combine the two, and you get the best of both worlds. 结合两者,您将获得两全其美的体验。 OSGi can be made to work alongside Maven using additional libraries such as Bnd and m2eclipse . 可以使用Bndm2eclipse等其他库使OSGi与Maven一起使用。

It sounds like an interesting approach, but personally I think it is best to manage build dependencies using an external build tool like Ant or Maven rather than tying your build to an IDE. 听起来这是一种有趣的方法,但我个人认为最好使用Ant或Maven等外部构建工具来管理构建依赖关系,而不是将构建与IDE绑定。 If you use maven and the m2eclipse plugin, it will automatically set up Eclipse project dependencies when loading the Maven POM if those other projects are also in your workspace. 如果您使用maven和m2eclipse插件,那么当其他项目也在您的工作空间中时,它将在装入Maven POM时自动设置Eclipse项目依赖项。

Unfortunately, if your team is currently using ad-hoc dependency management, it is kind of unlikely they will want to make the effort to jump to Maven. 不幸的是,如果您的团队当前正在使用临时依赖管理,那么他们不太可能会想跳到Maven。 Then again, maybe they just need a leader to spearhead the effort. 再说一遍,也许他们只需要一个领导者来带头努力。

I wouldn't use plug-in projects personally, I would use build tools such as Ant, Maven and others. 我不会亲自使用插件项目,而会使用Ant,Maven等构建工具。

If there's no build system integrated, it means that the company doesn't understand much about software development. 如果没有集成构建系统,则意味着该公司对软件开发的了解不多。

I wouldn't take all the responsibility to introduce a build system, possibly extra-hours. 我不会全权负责引入构建系统,可能要花几个小时。 If they don't want to migrate, I suggest that you start looking for another job ASAP. 如果他们不想迁移,建议您尽快开始寻找另一份工作。

There's two separate issues here. 这里有两个独立的问题。

  1. How do I set up multiple projects, and 如何设置多个项目,以及
  2. Which build system allows me to build multiple projects 哪个构建系统允许我构建多个项目

The two need not be related. 两者不必关联。 So, for example, you might choose Maven to build the projects but use plugin projects to enable easier editing. 因此,例如,您可以选择Maven来构建项目,但可以使用插件项目来简化编辑。 Most things beat the Eclipse build-system hands down; 大多数事情击败了Eclipse构建系统。 once it gets working, it's fairly stable - but getting it from nothing to working involves (a) luck, and/or (b) black magic. 一旦开始工作,它就相当稳定-但要使它从无到有地工作,将涉及(a)运气,和/或(b)黑魔法。

Ultimately, the question then comes down to which you feel easier managing; 最终,问题归结为您觉得更容易管理; both types of dependency, or just a single one. 两种类型的依赖关系,或仅一种依赖关系。 If you want a single one, then you need to invest the time in either something like m2eclipse (which generates project dependencies from the maven POM) or using pax-construct (which can generate the manifest from the maven POM). 如果您只想要一个,则需要花费时间在m2eclipse之类的东西上(它从maven POM生成项目依赖项),或者使用pax-construct(它可以从maven POM生成清单)。 Either that, or live with two dependency management systems. 要么,要么与两个依赖项管理系统一起使用。

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

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