简体   繁体   English

分发Java类库代码

[英]Distribution of java class library code

I need to put some old java class library code that I have into a repo, from where others can check it out and build it. 我需要将一些旧的Java类库代码放入回购中,其他人可以从那里签出并构建它。 You know, like any public repo. 就像任何公共回购一样。

But, I'm not sure what the best way to do this is in the java world. 但是,我不确定在Java世界中最好的方法是什么。 In old-fashioned projects, we just used to supply the build scripts and a list of dependencies. 在老式项目中,我们只是用来提供构建脚本和依赖项列表。 You gathered or installed the dependencies separately before running the build scripts. 在运行构建脚本之前,您分别收集或安装了依赖项。

But these days for many languages, you have package managers and the like that pull from remote locations and your build scripts need to include dependency fetching. 但是,如今对于许多种语言而言,您都具有从远程位置提取的程序包管理器等,并且您的构建脚本需要包含依赖项提取。

Basically, I'm not familiar with how java libs and programs are packaged. 基本上,我不熟悉如何打包Java库和程序。

Should I include the (dependency) libs in the repo? 我是否应该在仓库中包含(依赖)库? And update them whenever a new version is out? 并在有新版本发布时更新它们吗?

Does java now have a package manager that will pull in the latest versions of the dependencies? Java现在是否有一个软件包管理器,它将引入最新版本的依赖项?

Do I leave it upto the people checking out to download the libs themselves before they run the build scripts? 我是否要让那些签出代码的人自己在运行构建脚本之前自行下载这些库?

I'd prefer it if the solution didn't involve installing a huge package manager. 如果解决方案不涉及安装大型软件包管理器,我会更喜欢它。 Gradle wants to pull in like 150MB+ of stuff and as far as I am aware, it isn't ubiquitous on java deployments. Gradle希望提供150MB以上的内容,据我所知,它在Java部署中并不普遍。

Thanks. 谢谢。

Use Maven. 使用Maven。 I believe these days it's the #1 "package manager" (not a term that's usually used to describe it, but quite apt) by a large margin. 我相信这些天来已经是排名第一的“软件包管理器”(不是通常用来描述它的术语,但是很贴切)。 It's built into Netbeans, IntelliJ IDEA, and I believe Eclipse. 它内置于Netbeans,IntelliJ IDEA和Eclipse中。

However, it won't just "pull the latest versions" of your dependencies, since your application may break. 但是,由于您的应用程序可能会损坏,因此它不仅会“拉出”依赖项的最新版本。 Only the versions you specify. 仅您指定的版本。 Therefore, you should periodically update (and test) your code to reduce incompatibilities when someone tries to use your library in an application which directly or indirectly pulls newer versions of the same libs (and they get into a bit of "dll hell"), or reduce your use of third-party libraries in general. 因此,当有人尝试在直接或间接提取相同库的较新版本的应用程序中使用您的库时,您应该定期更新(和测试)您的代码,以减少不兼容的情况(并且它们会陷入“ dll地狱”的状况),或总体上减少使用第三方库。

You should also consider publishing your library in a compiled form to Maven Central so that using your library would be as easy as adding a dependency to the pom.xml. 您还应该考虑将库以已编译的形式发布到Maven Central,以便使用库就像将依赖项添加到pom.xml一样容易。 The problem that Maven solves, after all, is not so much making it easy to build your library (since just bundling the dependencies gets you most of the way), but making it easy to use your library. 毕竟,Maven解决的问题并不是要使构建库变得容易(因为捆绑依赖关系可以使您获得大部分收益),而是使使用库变得容易。

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

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