jenkins 如何从脱机计算机构建和发布Maven项目(文件目录为lib-repository)

gajydyqb  于 2022-11-02  发布在  Jenkins
关注(0)|答案(2)|浏览(212)

我需要使用Jenkins构建和发布项目,在一个无法访问Maven Central,甚至无法访问Nexus的服务器上。
假设我可以访问开发机器上的maven-central,以填充maven local_repository,我可以

mvn dependency:resolve-plugins dependency:go-offline

然后将local_repository复制到linux服务器上。
然后,为了避免Non-resolvable parent POM错误,如here所述,我用faked central profile填充了windows(dev)和linux(jenkins)的特定配置文件,以覆盖我的父pom所做的maven-central引用:

<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错误!,但是使用--legacy-local-repository选项建议使用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-repository,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.xml转换为maven-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放到本地lib库中。
"你有没有更好的解决方案,而不是痛苦的解决方案"

hk8txs48

hk8txs481#

您应该考虑设置一个本地存储库(例如,Nexus),您的构建计算机可以访问该存储库。
这是一种非常常见的设置。
它使您能够在没有Internet连接到构建计算机的情况下进行构建。

pwuypxnk

pwuypxnk2#

Maven部署插件可以解决这个问题。

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'

相关问题