gpt4 book ai didi

java - 如何在java项目中设置maven本地repo

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:44 25 4
gpt4 key购买 nike

我是 Maven 新手。我和我的团队正在尝试通过 git 使用 Maven,但是当我通过 git 共享代码时,.classpath 文件具有指向我的用户位置的依赖项:

<classpathentry kind="lib" path="C:/Users/MY_USERNAME/.m2/repository/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE.jar" sourcepath="C:/Users/MY_USERNAME/.m2/repository/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE-sources.jar">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="maven.groupId" value="org.springframework.security"/>
<attribute name="maven.artifactId" value="spring-security-crypto"/>
<attribute name="maven.version" value="5.1.0.RELEASE"/>
<attribute name="maven.scope" value="compile"/>
</attributes>
</classpathentry>

这会导致我的团队成员出现配置问题。

  • 有没有办法在我的项目中添加 .m2 文件夹,然后在构建路径中引用它?
  • 推荐吗?

我不想排除我的 .classpath 文件,因为我希望我的团队成员能够接收所有构建路径配置,而不必自己执行此操作。

最佳答案

Maven 与 Eclipse 插件捆绑在一起,该插件允许您根据 pom.xml(对于 Maven 1.x 用户而言为 project.xml)轻松维护 .classpath 文件(请参阅 docs )。

  • 初始设置

    要初始化 Maven 对更新 Eclipse 类路径的支持,您首先需要在 Eclipse 工作区中通过在 vim 中执行以下命令来设置 M2_REPO(或 MAVEN_REPO for 1.x))类路径变量:

    maven 2.x:

    :MvnRepo

    maven 1.x:

    :MavenRepo

  • 更新您的 .classpath

    执行初始设置后,更新 Eclipse .classpath 文件就像在命令行执行以下命令一样简单:

    maven 2.x:

    mvn eclipse:eclipse

    maven 1.x:

    maven eclipse

    或者在 Vim 中:

    maven 2.x:

    :Mvn eclipse:eclipse

    maven 1.x:

    :Maven eclipse

就您而言,每个团队成员每次想要了解彼此在 pom.xml 中更新的依赖项时都应该遵循此过程。

其他读物:

附加说明:

使用 Gradle 你可以这样做:

buildscript {
// ...
repositories {
mavenLocal() // this uses your local maven repository
// mavenCentral() // this uses maven central repository
// maven { url "<some-additional-url-here>" }
}
dependencies {
// ...
}
}

关于java - 如何在java项目中设置maven本地repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52741368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com