【问题标题】:Install Maven itself from Maven Central从 Maven Central 安装 Maven
【发布时间】:2012-06-26 14:15:21
【问题描述】:

我有一个 Maven 插件,我想针对不同的 Maven 版本进行测试(例如:2.2.1 和 3.0.4)。理想情况下,我不希望运行构建的用户必须手动安装这些确切的版本。

是否可以从 Maven Central 或其他一些源安装特定版本的 Maven,然后将它们缓存在本地 Maven 存储库中以供后续构建?

【问题讨论】:

  • 您可以使用“安装文件”插件将各种 Maven 版本上传到本地存储库。更好的是使用 Nexus(或 Archiva ...)部署您自己的 Maven 存储库。但归根结底,我认为@carlspring 是对的。这将作为一组在 Jenkins 上运行的 CI 作业来完成。然后,每次提交更改时,您的所有平台测试都可以自动触发以在后台安静地运行。
  • 澄清一下:我的目标是让构建在所有机器上完全可重现,而不仅仅是 CI 服务器,而且安装工作量最少。理想情况下,这应该是一个问题,或者从 scm 签出并使用您拥有的任何 mvn 版本运行构建。与 gradle 包装器概念不同...
  • 明白,但这不是书带问题吗?您需要 Maven 来安装 Maven,以便您可以运行 Maven ......正如您正确指出的那样,Gradle 通过它的包装器提供了一个解决方案...... Grails 还提供了从 ANT/ivy 和马文。问题是现在这些机制大部分都被破坏了,因为 Grails 得到了更好的支持。 Gradle 最终可能会发生这种情况,时间会证明一切......

标签: maven maven-2 maven-3


【解决方案1】:

Maven 发行版存储在 Maven Central Repository 中,您可以在此处看到:

因此,它可以用作具有以下坐标的普通依赖项:

tar.gz 变体:

<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>apache-maven</artifactId>
    <version>3.0.4</version>
    <classifier>bin</classifier>
    <type>tar.gz</type>
</dependency>

zip 变体:

<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>apache-maven</artifactId>
    <version>3.0.4</version>
    <classifier>bin</classifier>
    <type>zip</type>
</dependency>

其余部分非常标准 - 您可能会在集成测试 pom 中使用它,并按照 @khmarbaise 的建议使用 maven-invoker-plugin 调用它们。

【讨论】:

    【解决方案2】:

    您为什么不简单地安装一个持续集成 (CI) 服务器,例如 Jenkins / Hudson / TeamCity / 等? CI 服务器允许您针对不同版本的 SDK 运行构建。

    如果您的插件是 OSS(并且在 GitHub 上),我相信您可以从 Cloudbees 获得免费的 Jenkins 托管。

    无法从 Maven Central 下载 Maven 本身。您只能从他们的网站下载。

    【讨论】:

    • 我已经在 CI 服务器上使用了 Jenkins。请参阅我上面的评论。
    【解决方案3】:

    您可以执行以下操作:

       <profile>
          <id>run-its</id>
          <build>
            <!--  Download the different Maven versions -->
            <plugins>
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>1.0-beta-3</version>
                <executions>
                  <execution>
                    <id>download-maven-2.0.11</id>
                    <phase>prepare-package</phase>
                    <goals>
                      <goal>download-single</goal>
                    </goals>
                    <configuration>
                      <url>http://archive.apache.org/dist/maven/binaries/</url>
                      <fromFile>apache-maven-2.0.11-bin.tar.gz</fromFile>
                      <toDir>${project.build.directory}/maven/download/</toDir>
                    </configuration>
                  </execution>
                  <execution>
                    <id>download-maven-2.2.1</id>
                    <phase>prepare-package</phase>
                    <goals>
                      <goal>download-single</goal>
                    </goals>
                    <configuration>
                      <url>http://archive.apache.org/dist/maven/binaries/</url>
                      <fromFile>apache-maven-2.2.1-bin.tar.gz</fromFile>
                      <toDir>${project.build.directory}/maven/download/</toDir>
                    </configuration>
                  </execution>
                  <execution>
                    <id>download-maven-3.0.3</id>
                    <phase>prepare-package</phase>
                    <goals>
                      <goal>download-single</goal>
                    </goals>
                    <configuration>
                      <url>http://archive.apache.org/dist/maven/binaries/</url>
                      <fromFile>apache-maven-3.0.3-bin.tar.gz</fromFile>
                      <toDir>${project.build.directory}/maven/download/</toDir>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
    
    
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>truezip-maven-plugin</artifactId>
                <version>1.0-beta-4</version>
                <executions>
                  <execution>
                    <id>extract-maven-2.0.11</id>
                    <goals>
                      <goal>copy</goal>
                    </goals>
                    <phase>prepare-package</phase>
                    <configuration>
                      <fileset>
                        <directory>${project.build.directory}/maven/download/apache-maven-2.0.11-bin.tar.gz</directory>
                        <outputDirectory>${project.build.directory}/maven/tools/</outputDirectory>
                      </fileset>
                    </configuration>
                  </execution>
                  <execution>
                    <id>extract-maven-2.2.1</id>
                    <goals>
                      <goal>copy</goal>
                    </goals>
                    <phase>prepare-package</phase>
                    <configuration>
                      <fileset>
                        <directory>${project.build.directory}/maven/download/apache-maven-2.2.1-bin.tar.gz</directory>
                        <outputDirectory>${project.build.directory}/maven/tools/</outputDirectory>
                      </fileset>
                    </configuration>
                  </execution>
                  <execution>
                    <id>extract-maven-3.0.3</id>
                    <goals>
                      <goal>copy</goal>
                    </goals>
                    <phase>prepare-package</phase>
                    <configuration>
                      <fileset>
                        <directory>${project.build.directory}/maven/download/apache-maven-3.0.3-bin.tar.gz</directory>
                        <outputDirectory>${project.build.directory}/maven/tools/</outputDirectory>
                      </fileset>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
    
              <!--
                This is currently needed due to a bug of the truezip-plugin cause it unpacks without permission!
                see http://jira.codehaus.org/browse/MOJO-1796
               -->
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                      <id>chmod-files</id>
                      <phase>package</phase>
                      <goals>
                        <goal>run</goal>
                      </goals>
                      <configuration>
                        <target>
                          <chmod file="${project.build.directory}/maven/tools/apache-maven-2.0.11/bin/mvn" perm="+x"/>
                          <chmod file="${project.build.directory}/maven/tools/apache-maven-2.2.1/bin/mvn" perm="+x"/>
                          <chmod file="${project.build.directory}/maven/tools/apache-maven-3.0.3/bin/mvn" perm="+x"/>
                        </target>
                      </configuration>
                    </execution>
                  </executions>
              </plugin>
    
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-invoker-plugin</artifactId>
                <version>1.5</version>
                <dependencies>
                  <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy</artifactId>
                    <version>1.8.4</version>
                  </dependency>
                </dependencies>
                <configuration>
                  <debug>false</debug>
                      <!-- src/it-ip as for integration tests invoker plugin for the time of transition to maven-invoker-plugin -->
                  <projectsDirectory>src/it</projectsDirectory>
                  <showVersion>true</showVersion>
                  <pomIncludes>
                    <pomInclude>*/pom.xml</pomInclude>
                  </pomIncludes>
                  <preBuildHookScript>setup</preBuildHookScript>
                  <postBuildHookScript>verify</postBuildHookScript>
                  <settingsFile>src/it/settings.xml</settingsFile>
                </configuration>
                <executions>
                  <execution>
                    <id>integration-test-maven-2.0.11</id>
                    <goals>
                      <goal>install</goal>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                      <reportsDirectory>${project.build.directory}/invoker-reports-2.0.11</reportsDirectory>
                      <localRepositoryPath>${project.build.directory}/local-repo-2.0.11</localRepositoryPath>
                      <cloneProjectsTo>${project.build.directory}/it-2.0.11</cloneProjectsTo>
                      <mavenHome>${project.build.directory}/maven/tools/apache-maven-2.0.11</mavenHome>
                      <goals>
                        <goal>clean</goal>
                        <goal>test</goal>
                      </goals>
                    </configuration>
                  </execution>
                  <execution>
                    <id>integration-test-maven-2.2.1</id>
                    <goals>
                      <goal>install</goal>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                      <reportsDirectory>${project.build.directory}/invoker-reports-2.2.1</reportsDirectory>
                      <localRepositoryPath>${project.build.directory}/local-repo-2.2.1</localRepositoryPath>
                      <cloneProjectsTo>${project.build.directory}/it-2.2.1</cloneProjectsTo>
                      <mavenHome>${project.build.directory}/maven/tools/apache-maven-2.2.1</mavenHome>
                      <goals>
                        <goal>clean</goal>
                        <goal>test</goal>
                      </goals>
                    </configuration>
                  </execution>
                  <execution>
                    <id>integration-test-maven-3.0.3</id>
                    <goals>
                      <goal>install</goal>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                      <reportsDirectory>${project.build.directory}/invoker-reports-3.0.3</reportsDirectory>
                      <localRepositoryPath>${project.build.directory}/local-repo-3.0.3</localRepositoryPath>
                      <cloneProjectsTo>${project.build.directory}/it-3.0.3</cloneProjectsTo>
                      <mavenHome>${project.build.directory}/maven/tools/apache-maven-3.0.3</mavenHome>
                      <goals>
                        <goal>clean</goal>
                        <goal>test</goal>
                      </goals>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
            </plugins>
          </build>
        </profile>
    

    这将下载不同的 Maven 版本,解压 .tar.gz 档案并使 mvn 可执行并使用 maven-invoker-plugin 运行所有与这些不同 maven 版本的集成测试。

    但是我不建议这样做。更好的方法是使用包含不同 Maven 安装的 CI 解决方案(如前所述)。您可以分别为每个 Maven 版本运行集成测试。

    【讨论】:

    • 真是个怪物! +1 不推荐!
    猜你喜欢
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2012-04-01
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    相关资源
    最近更新 更多