首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Maven Central安装Maven本身

从Maven Central安装Maven本身
EN

Stack Overflow用户
提问于 2012-06-26 22:15:21
回答 3查看 551关注 0票数 2

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

是否可以从Maven Central或其他来源安装特定版本的Maven本身,然后将其缓存到本地Maven存储库中,以供后续构建使用?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-07 06:48:37

Maven发行版存储在Maven Central Repository中,如下所示:

因此,它可以用作具有以下坐标的正常依赖:

tar.gz变体:

代码语言:javascript
复制
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>apache-maven</artifactId>
    <version>3.0.4</version>
    <classifier>bin</classifier>
    <type>tar.gz</type>
</dependency>

zip变体:

代码语言:javascript
复制
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>apache-maven</artifactId>
    <version>3.0.4</version>
    <classifier>bin</classifier>
    <type>zip</type>
</dependency>

其余的是非常标准的-你可能会在集成测试poms中使用它,并按照@khmarbaise推荐的方式用maven-invoker-plugin调用它们。

票数 1
EN

Stack Overflow用户

发布于 2012-06-26 22:40:38

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

如果你的插件是开源的(在GitHub上),我相信你可以从Cloudbees获得免费的Jenkins主机。

从Maven Central下载Maven本身是不可能的。你只能从他们的网站上下载。

票数 1
EN

Stack Overflow用户

发布于 2012-06-27 03:10:34

你可以做如下的事情:

代码语言:javascript
复制
   <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版本的所有集成测试。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11209329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档