如何将 Bundle-classpath jar 及其依赖项从 Maven 存储库复制到我的本地 lib 文件夹?

发布于 2024-11-18 21:14:09 字数 3835 浏览 3 评论 0 原文

我们正在开发一个 Eclipse RCP 应用程序。我们决定使用SVN作为版本控制系统。我们可以在 eclipse 环境中导出 eclipse 产品。一切都很好。

但是,

我们的一些插件依赖于在其manifest.mf中使用bundle-classpath的常规java jar。到目前为止,我们正在将这些 jar 提交到 SVN 存储库中。我们“听说”将 jar 提交到 svn 是错误的,我们应该使用 ma​​ven-tycho 并将这些 jar 放入 Maven 存储库中以实现此目的。

因此,我们将 jar 从 SVN 存储库移至 Maven 存储库。然后我们想设置一个新的开发环境,我们从 svn 检查了项目,他们有编译错误,因为我们没有 jars!

我们使用 m2eclipse 并在新创建的 pom.xml 文件中定义所有依赖项。 ma​​ven-dependency-plugin 的复制目标并列出所有 jar,然后运行 ​​mvn validate 将 jar 放入我们的 lib 文件夹中。它有效,但在我看来有点难看。因为我的插件的 pom.xml 看起来像定义每个依赖项两次:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copy-bundle-classpath-libs</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>lib</outputDirectory>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <stripVersion>true</stripVersion>
                        <artifactItems>
                            <artifactItem>
                                <groupId>MyGroup</groupId>
                                <artifactId>MyJar</artifactId>
                                <version>SNAPSHOT</version>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>MyGroup</groupId>
        <artifactId>MyJar</artifactId>
        <version>SNAPSHOT</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

有没有办法摆脱这个?

此外,如果 MyJar.pom 有其他依赖项,我在本地库中也需要它们。有没有办法将这些传递依赖项复制到我的本地 lib 文件夹

我尝试了复制依赖项目标,但它试图找到我的插件所依赖的其他插件的jar。我只需要将常规 jar 复制到本地库即可。我的其他插件已经作为插件项目与其所有源代码并排存在。我不需要他们的罐子。我可以过滤掉那些吗?我尝试过但没有成功:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <configuration>
                <excludeGroupIds>MyGroup</excludeGroupIds>
                <outputDirectory>lib</outputDirectory>
                <overWriteReleases>true</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <stripVersion>true</stripVersion>
            </configuration>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

谢谢

We are developing an Eclipse RCP application. We decided to use SVN for revision control system. We could export an eclipse product in the eclipse environment. Everything worked fine.

But,

Some of our plugins have dependencies to regular java jars using bundle-classpath in their manifest.mf. Up to now we were committing those jars into SVN repository. We "heard" that it is wrong to commit jars into svn and we should use maven-tycho and put those jars into a maven repository for this purpose.

So we moved the jars from SVN repository to Maven repository. Then we wanted to setup a fresh dev environment, we checked out projects from svn and they had compilation errors because we do not have jars!

We used m2eclipse and define all dependencies in my freshly created pom.xml files. maven-dependency-plugin's copy goal and list all the jars and then we run mvn validate to get the jars into our lib folder. It worked but it seems to me a bit ugly. Because my plugin's pom.xml looks like defining every dependency twice:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copy-bundle-classpath-libs</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>lib</outputDirectory>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <stripVersion>true</stripVersion>
                        <artifactItems>
                            <artifactItem>
                                <groupId>MyGroup</groupId>
                                <artifactId>MyJar</artifactId>
                                <version>SNAPSHOT</version>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>MyGroup</groupId>
        <artifactId>MyJar</artifactId>
        <version>SNAPSHOT</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

Is there a way to get rid of this?

Besides if MyJar.pom has other dependencies I need them too in my local lib. Is there a way to copy those transitive dependencies to my local lib folder?

I tried copy-dependencies goal but it tries to find my other plugins' jars that my plugin depends on. I just need the regular jars to be copied to my local lib. My other plugins are already there side by side with all their source code as a plugin project. I do not need their jars. Can I filter those out? I tried this without success:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <configuration>
                <excludeGroupIds>MyGroup</excludeGroupIds>
                <outputDirectory>lib</outputDirectory>
                <overWriteReleases>true</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <stripVersion>true</stripVersion>
            </configuration>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞旧 2024-11-25 21:14:09

您需要决定是否要复制传递依赖项。

maven-dependency-plugin [1] 允许复制传递依赖项(“复制依赖项”目标,需要仅在 pom 中将依赖项添加到依赖项部分)或仅复制某些没有传递依赖项的工件(“复制”目标,需要添加工件仅适用于插件的配置部分)。
使用复制依赖项时,您还可以在传递依赖项链中包含/排除某些artifactId,请参阅[2]。

--

[1] http://maven.apache.org/plugins/maven-dependency -plugin/

[2] http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependency-mojo.html

you need to decide whether you want transitive dependencies copied or not.

maven-dependency-plugin [1] allows to copy either transitive dependencies ("copy-dependencies" goal, need to add dependencies to dependencies section only in pom) or just certain artifacts without transitive dependencies ("copy" goal, need to add artifacts to plugin's configuration section only).
When using copy-dependencies, you can also include/exclude certain artifactIds from the transitive dependency chain, see [2].

--

[1] http://maven.apache.org/plugins/maven-dependency-plugin/

[2] http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文