15

I need to build and release projects using Jenkins, on a server with no access to maven central, and even, with no access to Nexus.

Given that I have access to maven-central on dev machines, to fill the maven local_repository, I could do

mvn dependency:resolve-plugins dependency:go-offline

to then copy the local_repository on the linux server.

Then, to get ride of a Non-resolvable parent POM error, as described here, I filled the specific profiles for both windows (dev) and linux (jenkins) with faked central profile to override the maven-central reference made by my parent pom:

    <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>

That way, mvn -o compile still raise a Non-resolvable parent POM error !, but using the --legacy-local-repository option suggested here , managed to fake the remote repository by using a local one, and the Non-resolvable parent POM problem disappeared:

mvn --legacy-local-repository compile

Still, a strange error appeared (decribed 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]

But it was hiding an earlier warning:

[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)

Using --legacy-local-repository, maven seems to use the distribution repository path as the local libs repository !

I swapped them in the 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>
...

and had also to copy into the local repository: all maven-metadata-maven2_central.xml into maven-metadata.xml

using the following bash command:

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

And ... BINGO !

BUILD SUCCESSFULL

Seems weird, at later stage, to release:perform into the local lib repository.

Would you have any better and not that painful solution ?

Community
  • 1
  • 1
user1767316
  • 3,276
  • 3
  • 37
  • 46

2 Answers2

1

Maven deploy plugin would solve this problem.

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

More Exhaustive example:


# 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'
Janardhan
  • 51
  • 6
  • Actual usage here: https://github.com/j143/systemds/blob/cf87232b298ab708b20d30cdfd42d5ba3c1366f9/dev/release/release-build.sh#L172-L194 – Janardhan Nov 09 '21 at 07:20
0

You should consider setting up a local repository (for example, Nexus) that will be accessible to your build machine.

This is a very common setup.

It enables you to build without internet connection to the build machine.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156