Codex unable to access java maven repository

I am getting the following error when i try to compile using mvn.

./mvnw clean test

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/3.3.8/spring-boot-dependencies-3.3.8.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: The following artifacts could not be resolved: org.springframework.boot:spring-boot-dependencies:pom:3.3.8 (absent): Could not transfer artifact org.springframework.boot:spring-boot-dependencies:pom:3.3.8 from/to central (https://repo.maven.apache.org/maven2): Network is unreachable @ line 39, column 16
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter:jar is missing. @ line 169, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-web:jar is missing. @ line 173, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-data-jpa:jar is missing. @ line 182, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-validation:jar is missing. @ line 186, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-test:jar is missing. @ line 190, column 21
 @ ```
1 Like

Okay, seems like we need to use correct proxy. Here is a small startup-script that installs dependencies using maven 3.9.9! Same can of course be done using mvnw, this is just simplified (and not yet fully optimised, more a proof of concept):

#!/bin/sh

version=3.9.9
url="https://dlcdn.apache.org/maven/maven-3/${version}/binaries/apache-maven-${version}-bin.tar.gz"
echo $url
wget $url

sleep .4

tarFile="apache-maven-${version}-bin.tar.gz"
echo $tarFile
sudo tar -xvf $tarFile -C /opt/

export PATH=/opt/apache-maven-${version}/bin:$PATH
echo -e "\nPATH=\"/opt/apache-maven-${version}/bin:\$PATH\"" >> ~/.profile

mkdir -p ~/.m2 && cat > ~/.m2/settings.xml <<EOF
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              https://maven.apache.org/xsd/settings-1.0.0.xsd">
</settings>
EOF

sed -i '/<\/settings>/ i\
  <proxies>\
    <proxy>\
      <id>defaultProxy</id>\
      <active>true</active>\
      <protocol>http</protocol>\
      <host>proxy</host>\
      <port>8080</port>\
    </proxy>\
    <proxy>\
      <id>defaultSecureProxy</id>\
      <active>true</active>\
      <protocol>https</protocol>\
      <host>proxy</host>\
      <port>8080</port>\
    </proxy>\
  </proxies>' ~/.m2/settings.xml
mvn dependency:go-offline -X
2 Likes

I have the same issue, oddly if I use your proxy fix in the environment setup and use the interactive terminal there it does fix the issue. But when I actually come to use the environment it fails in the same way with network connectivity issues in the startup script even though I can see its running the same sed cmd etc.

Thank you for your reply!

How can we make it work with gradle?

Thanks, this was very helpful!

Anyone know how to make it work with a private maven repo (github packages)?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.8.1:go-offline (default-cli) on project my-project: org.eclipse.aether.resolution.DependencyResolutionException: Failed to read artifact descriptor for com.mycompany.myproject:jar:version: Could not transfer artifact descriptor for com.mycompany.otherproject:jar:version from/to github (https://maven.pkg.github.com/mycompany/*): authentication failed for https://maven.pkg.github.com/..., status: 401 Unauthorized -> [Help 1]

Codex has access to our github repositories, but not our github packages. Anyone know how to solve that?

To answer my own question, the key was to add the repository to settings.xml and configure the token using Codex secrets.

cat > ~/.m2/settings.xml <<EOF
<settings>
  <proxies>
    <proxy>
      <id>codexProxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy</host>
      <port>8080</port>
    </proxy>
  </proxies>

...

        <repository>
          <id>github</id>
          <url>https://maven.pkg.github.com/mycompany/*</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>

...

  <servers>
    <server>
      <id>github</id>
      <username>\${env.GITHUB_ACTOR}</username>
      <password>\${env.GITHUB_TOKEN}</password>
    </server>
  </servers>

</settings>
EOF

Then configure GITHUB_ACTOR and GITHUB_TOKEN in Codex environment secrets.

This is my solution using mirroring and preloading the plugins -

#!/bin/bash
set -e

echo "[INFO] Installing Maven..."
apt update && apt install -y maven curl unzip

echo "[INFO] Setting up Maven to use local repository only..."
mkdir -p /root/.m2

cat <<EOF > /root/.m2/settings.xml
<settings>
  <mirrors>
    <mirror>
      <id>local-repo</id>
      <mirrorOf>*</mirrorOf>
      <url>file:///root/.m2/repository</url>
    </mirror>
  </mirrors>
</settings>
EOF

echo "[INFO] Downloading Maven plugin: jmeter-maven-plugin:3.8.0 and dependencies..."
BASE_URL="https://repo1.maven.org/maven2"
M2_REPO="/root/.m2/repository"

# Utility function
download_artifact() {
  GROUP_ID="$1"
  ARTIFACT_ID="$2"
  VERSION="$3"

  GROUP_PATH=$(echo "$GROUP_ID" | tr '.' '/')
  TARGET_DIR="$M2_REPO/$GROUP_PATH/$ARTIFACT_ID/$VERSION"
  ARTIFACT_URL="$BASE_URL/$GROUP_PATH/$ARTIFACT_ID/$VERSION"

  mkdir -p "$TARGET_DIR"
  cd "$TARGET_DIR"

  for ext in pom jar; do
    FILE="$ARTIFACT_ID-$VERSION.$ext"
    if [ ! -f "$FILE" ]; then
      echo "[INFO] Downloading $FILE"
      curl -s -O "$ARTIFACT_URL/$FILE"
      touch "$FILE.lastUpdated"
    fi
  done
}

# Main plugin
download_artifact "com.lazerycode.jmeter" "jmeter-maven-plugin" "3.8.0"

# Known direct dependencies of jmeter-maven-plugin:3.8.0
# (Extracted from POM at https://repo1.maven.org/maven2/com/lazerycode/jmeter/jmeter-maven-plugin/3.8.0/jmeter-maven-plugin-3.8.0.pom)

download_artifact "org.apache.maven.plugins" "maven-plugin-plugin" "3.6.0"
download_artifact "org.apache.maven" "maven-plugin-api" "3.6.3"
download_artifact "org.apache.maven" "maven-core" "3.6.3"
download_artifact "org.apache.maven" "maven-artifact" "3.6.3"
download_artifact "org.codehaus.plexus" "plexus-utils" "3.2.0"
download_artifact "org.codehaus.plexus" "plexus-archiver" "4.2.3"
download_artifact "org.slf4j" "slf4j-api" "1.7.36"
download_artifact "commons-io" "commons-io" "2.11.0"
download_artifact "org.sonatype.oss" "oss-parent" "9"

echo "[INFO] Preloading done. You can run maven now in offline mode: mvn clean install --offline"