maven - Jenkins Maven 存储库中的备份文件夹

标签 maven jenkins gradle

我在 Windows 系统上使用 Jenkins 和 gradle 构建。
Jenkins 在内部使用maven。我的文件夹结构很糟糕
C:\users\.m2\repository\\
在 modulename 文件夹中,我有多个文件夹,其版本如下
1.0.1
1.0.2
...
1.0.50。
谁能告诉我为什么我们每天都创建这些文件夹。
丢弃或减少文件夹是个好主意吗?如果是,我们如何实现这一点。

最佳答案

Maven 根据您所有项目 (pom.xml) 中的声明解析依赖项的版本。

如果项目 A 有:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>

和项目 B 有:
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8</version>
</dependency>

然后您将在 .m2 目录中同时拥有 4.8 和 4.12 版本。

我建议您创建一个 BOM( Material list ),而不是先删除“旧”版本。

它就像一个技术模块,您可以在其中修复所有依赖项和插件版本。然后你必须在你的 Maven 项目中使用它。之后,您可以删除 .m2 中太旧的 jar。

BOM 导入示例:
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>xxx</groupId>
  <artifactId>xyz</artifactId>
  <packaging>jar</packaging>
  <name>My project</name>
  <version>1.0</version>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>X</artifactId>
        <version>1.0</version>
        <type>pom</type>
       <scope>import</scope>
      </dependency>
      </dependencies>
  </dependencyManagement>
</project>

关于maven - Jenkins Maven 存储库中的备份文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32888370/

相关文章:

java - 从 @controller 读取 Spring 配置文件

networking - 无法使用端口 8080 访问在 Raspberry Pi 上运行的 Jenkins

jenkins - 在 Jenkins 声明式管道中使用 waitForQualityGate

intellij-idea - 无法制作模块: related gradle configuration was not found. 请重新导入Gradle项目并重试

android - 错误夸大设计支持库中的任何内容

android - 如何使用 gradle 为 3rd 方部门管理不同的支持库版本?

java - 为特定groupId生成依赖关系图

java - 如何为我的 NetBeans 模块 Maven 设置集群

java - 不兼容 :org. codehaus.plexus。 .exception.ComponentLookupException

java - 如何对 Jenkins 运行构建和清理命令?