0

我有一个大型 Maven 项目,其中包含许多基于 Maven 的子项目。

我开始使用 Red5,red5 创建了一个基于 ivy 的项目。我需要将该项目添加到依赖项中。

列出项目主目录的文件:

build.properties  build.xml  ivy.xml  ivysettings.xml  lib  readme.txt  src  www

如何将此项目添加为 Maven 项目依赖项之一?

在 Maven 3.0.4 中使用 Java

谢谢!克菲尔

4

3 回答 3

1

Interesting... A lib directory in an Ivy project.

You can modify the build.xml to create one more target that calls the <ivy:makepom/> target. Just make sure that <ivy:resolve> is called first. This will create a small piece of the pom.xml file you need.

As for the rest. What's that technical term? Oh yeah, you're screwed.

The problem is that Ant and Maven have two completely different build philosophies. In Ant, you write a build.xml script that describes what you want to build and how you want to build it. In Maven, you describe your project via a pom.xml file, and Maven does all the build processing for you.

This isn't an issue of whether or not Whether Ant or Maven is the force of all that's good in the world and the other is only for luzers Apple Fanboys. This is a case of manually converting a pre-existing project into Maven.

You'll have to go through your build.xml and figure out everything it is doing. Then, you need to convert this over to a Maven pom.xml file. There's no way to automate this. Even worse, Red5 isn't setup like a Maven project, so you'll either have to move all the files around, or go into archaic pom.xml configuration hell trying to override how Maven assumes the build is suppose to take place. This can take days, even weeks to get right. And, in the end, you end up with a project you don't control that if you want to update will have to be done all over again from scratch.

Trust me, I did this before for another job where the System Architect decided that Maven was better than Ant, and all of our projects must be converted from Ant to Maven. And, who got stuck with this task? Not the developers who were too busy with other tasks, but I the Configuration Manager.

And, in the end, you will have a project you don't control that if you want to update will have to be done all over again from scratch.


There is an alternative: Ignore it.

Does it really matter if Red5 is an Ivy project? What do you need from this Red5 project anyway? Do you need that red5.jar or the distribution that gets built.

If you need the distribution, let it remain as an Ivy project. Simply set the ivysettings.xml to point to your Maven repository and let it know that it's in Maven 2 format. Ivy will have no problems getting stuff out of that. So what if it's Ivy?

If you just need that red5.jar file in your other Maven project, you can simply use the <ivy:makepom/> task to generate a pom.xml file for you. Then use mvn deploy:deploy-file to deploy that jar into your Maven repository:

 $ mvn deploy:deploy-file -Dfile=red5.jar \
     -DpomFile=pom.xml \
     -DrepositoryId=$repoId \
     -Durl=$url

Now, your red5.jar is in your Maven repository as a fully transitive downloading jar. If you really, really want to get fancy, you can embed the generated pom.xml file into the jar itself, so it is self referential just like Maven jars are. That will take about 30 minutes of hacking the current build.xml file. (Or, if your jar doesn't have to have the pom.xml embedded in it, a separate Ant file that just builds the pom.xml you need, and maybe even deploys it into your Maven repository for you. That way, if the project gets updated, you don't have to worry about the build.xml file being updated.

于 2012-11-21T15:50:06.973 回答
0

我认为您不会在不创建 JAR 的情况下侥幸逃脱。Maven 的整个依赖理念是围绕存储库中的 JAR 文件构建的——当一个 maven 项目依赖于另一个项目时,它的工作方式是依赖项目构建其 JAR 并将其放入本地存储库,然后主项目从那里依赖它。

也就是说,您可以使用Maven Ant Tasks<ivy:makepom>Maven Ant Tasks的组合相当轻松地自动执行此操作。这个想法是让 Ivy 项目构建它的 JAR 并将其作为每个构建的一部分推送到本地 Maven 存储库,因此它可以立即供 maven 项目依赖。

<jar destfile="project.jar">
   <fileset dir="classes" />
</jar>

<ivy:makepom ivyfile="ivy.xml" pomfile="project.pom" conf="default,runtime">
   <mapping conf="default" scope="compile"/>
   <mapping conf="runtime" scope="runtime"/>
</ivy:makepom>

<artifact:pom id="project.pom" file="project.pom" />
<artifact:install file="project.jar" pomRefId="project.pom" />

确保您的 Ivy 项目的版本号-SNAPSHOTivy.xml.

于 2012-11-21T16:08:45.377 回答
0

我自己没有使用过它,但我知道 Ivy 有一个任务可以将 ivy 文件转换为 maven pom。 我将探索一个选项,让我的 CI 环境运行该任务以在成功构建后生成一个 pom,然后让我的 maven 项目查看 CI 的 jar 和 pom 的最新工件。您也可以跳过 CI 环境,并让 maven 从本地文件系统解析工件。

于 2012-11-21T13:33:17.507 回答