如何在脱机机器上构建和发布Maven项目(使用文件目录作为lib存储库) [英] How to build and release a Maven project from an offline machine (with a file directory as lib-repository)

查看:0
本文介绍了如何在脱机机器上构建和发布Maven项目(使用文件目录作为lib存储库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Jenkins构建和发布项目, 在无法访问Maven Central,甚至无法访问Nexus的服务器上。

假设我有权访问开发机器上的Maven-Central, 要填充maven local_store,我可以执行以下操作

mvn dependency:resolve-plugins dependency:go-offline

然后将本地存储库复制到Linux服务器上。

然后,为了避免Non-resolvable parent POM错误, 如here所述,我用伪造的中央配置文件填充了Windows(Dev)和Linux(Jenkins)的特定配置文件,以覆盖我的父级pom:

所做的maven-center引用
    <profiles>
        <profile>
            <id>windows</id>
            <activation>              
              <os>
                <family>Windows</family>
              </os>
            </activation>
            <properties>                <repository.base.url>file:///c:/maven_distribution_repo/</repository.base.url>
            </properties>           
        </profile>
        <profile>
            <id>linux</id>
            <activation>              
              <os>
                <family>Linux</family>
              </os>
            </activation>
            <properties>
<repository.base.url>file:///appli/Maven_3.1.1_build/maven_distribution_repo/</repository.base.url>         
            </properties>           
            <repositories>
                <repository>
                  <id>central</id>
                  <name>Maven Plugin Repository</name>
                  <!--<url>http://repo1.maven.org/maven2</url>-->
                  <url>${repository.base.url}</url>
                  <releases>
                    <enabled>false</enabled>
                  </releases>
                </repository>   
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <name>Maven Plugin Repository</name>
                    <!--<url>http://repo1.maven.org/maven2</url>-->
                    <url>${repository.base.url}</url>
                    <layout>default</layout>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <releases>
                            <updatePolicy>never</updatePolicy>
                        </releases>
                </pluginRepository>
            </pluginRepositories> 
        </profile>
    </profiles>
这样,mvn -o compile仍然会引发Non-resolvable parent POM错误!, 但使用建议的选项here, 设法通过使用本地存储库来伪造远程存储库, Non-resolvable parent POM问题消失:

MVN--旧版本地存储库编译

仍然出现奇怪的错误(描述here):

[ERROR] Failed to execute goal on project myProject: Could not resolve dependencies for project some.package:myProject:war:0.0.7-SNAPSHOT: Failed to collect dependencies at org.jxls:jxls-poi:jar:1.0.11 -> org.jxls:jxls:jar:[2.0.0,):  org.jxls:jxls:jar:[2.0.0,) within specified range -> [Help 1]

但它隐藏了先前的警告:

[WARNING] Could not transfer metadata org.jxlsjxls/maven-metadata.xml from/to central (/path):/appli/Maven_3.1.1_build/maven_distribution_repo/org/jxls/jxls/maven-metadata-central.xml (access forbidden)

通过使用--Legacy-local-store,Maven似乎将分发存储库路径用作本地libs存储库!

我在POM中调换了它们:

                <profile>
                    <id>linux</id>
                    <activation>              
                      <os>
                        <family>Linux</family>
                      </os>
                    </activation>
                    <properties>    
    <!--<repository.base.url>file:///appli/Maven_3.1.1_build/maven_distribution_repo/</repository.base.url>-->
    <repository.base.url>file:///appli/Maven-3.1.1_build/maven_local_repo/</repository.base.url>
                    </properties>
...

还必须复制到本地存储库中: 全部maven-metadata-maven2_central.xmlmaven-metadata.xml

使用以下bash命令:

for file in $(find /appli/Maven-3.1.1_build/maven_local_repo -type f -name 'maven-metadata-maven2_central.xml'); do cp $file $(echo ${file%/*}/maven-metadata.xml); done

和...答对了!

生成成功

在以后的阶段,release:perform进入本地库存储库似乎很奇怪。

您还有更好且不那么痛苦的解决方案吗?

推荐答案

Maven Deploy插件可以解决此问题。

mvn deploy -DaltDeploymentRepository=local-temp::default::file://directory/

更详尽的示例:


# 1. Create temporary folder
tmp_repo=$(mktemp -d systemds-repo-tmp-XXXXX)


# 2. Create a simple settings.xml
  cat <<EOF >../tmp-settings-nexus.xml
<settings>
<activeProfiles>
    <activeProfile>local-temp</activeProfile>
  </activeProfiles>
  <profiles>
    <profile>
      <id>local-temp</id>
      <repositories>
        <repository>
          <id>local-temp</id>
          <url>${tmp_repo}</url>
        </repository>
      </repositories>
    </profile>
  </profiles>
</settings>
EOF


# 3. deploy to local
  mvn --settings ../tmp-settings-nexus.xml -Pdistribution deploy 
    -DaltDeploymentRepository=local-temp::default::file://${tmp_repo} 
    -Daether.checksums.algorithms='SHA-512,SHA-1,MD5'

这篇关于如何在脱机机器上构建和发布Maven项目(使用文件目录作为lib存储库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆