2

In our Java SpringBoot project we are using GitHub actions to run SonarScan. It was working like a charm until I've added first custom library to the project. That library is in Nexus repo and accessible only via VPN.

Locally project is built without any issues and works fine. Unit-testing and dev deployment GH actions run successfully. But SonarScan action is failing on :compileJava because of the missing resource (log below).

Looks like it tries to get it from the Apache Maven although it is in the Nexus. Here is the relevant part of the log:

> Task :compileJava
Watching 37 directories to track changes
Resolving global dependency management for project 'project_name'
Resource missing. [HTTP GET: https://repo.maven.apache.org/maven2/com/company_name/lib_name/1.0.7-SNAPSHOT/maven-metadata.xml]
Resource missing. [HTTP GET: https://repo.maven.apache.org/maven2/com/company_name/lib_name/1.0.7-SNAPSHOT/lib_name-1.0.7-SNAPSHOT.pom]
Excluding []


FAILURE: Build failed with an exception.
> Task :compileJava FAILED
* What went wrong:
:compileJava (Thread[included builds,5,main]) completed. Took 4 mins 35.418 secs.
1 actionable task: 1 executed
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve com.company_name:lib_name:1.0.7-SNAPSHOT.

     Required by:
         project :
      > Skipped due to earlier error

Here is our build.gradle file (shortened):

plugins {
    id 'org.springframework.boot' version '2.6.4'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'java-library'
    id "org.sonarqube" version "3.3"
}


//Sets Java Version
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}

ext {
    set('mongoVersion', '4.4.1')
    set('mavenUsername', "maven.user")
    set('mavenPassword', "password")
    set('mavenUrl', "https://nexus-repo-url/repository/repo-name")
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    maven {
        credentials {
            username "${mavenUsername}"
            password "${mavenPassword}"
        }
        url "${mavenUrl}"
        authentication {
            basic(BasicAuthentication)
        }
    }
}

dependencies {
    ...
    implementation "com.company_name:lib_name:1.0.7-SNAPSHOT"
}


sonarqube {
    properties {
        property "sonar.projectKey", "prject_key"
        property "sonar.java.binaries", "build/classes"
    }
}

I am obviously missing some path somewhere, but failing to find where actually.

7
  • 1
    As stated in the Gradle documentation (docs.gradle.org/current/userguide/…) "A project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module." What happens if you try to declare maven (the Nexus repo) first and mavenCentral second?
    – qdoot
    Commented Aug 22, 2022 at 9:54
  • 1
    How is the VPN configured in the github action? Are you able to reach the nexus repo from the github action at all, i. e. does curl https://nexus-repo-url/repository/repo-name -u "user:password" work? Commented Aug 22, 2022 at 18:57
  • @qdoot, good catch, but I've tried that already: order has no matter. This change actually changed output logs highlighting that it tried to connect our Nexus and got Connect Timeout. So, that brings up Bragolgirith's point: Is Nexus reach-able from GH actions. Checking. Commented Aug 24, 2022 at 10:23
  • run network test through github and nexus. (telnet or curl) Commented Aug 25, 2022 at 11:55
  • 1
    so if other GH actions can build the project, then the next guess that you need the same networking configs for the Sonar action, maybe that was not set up by you and you missed it? @YehorLevchenko Commented Aug 25, 2022 at 15:20

2 Answers 2

0
Could not resolve com.company_name:lib_name:1.0.7-SNAPSHOT.

which seems to be populated by

dependencies {
    ...
    implementation "com.company_name:lib_name:1.0.7-SNAPSHOT"
}

uneducated guess says you're most likely relying on com.company_name and lib_name to be supplied as arguments to your code.

which is kind of weird since you're treating it as a dependency, not a parameter.

it's difficult to imagine the context of that application, but checking whether my repo contains com.company_name and/or lib_name etc etc snapshot is where i'd start.

5
  • Not true, dependency is provided as a string, without any variables. Commented Aug 24, 2022 at 10:47
  • evidently, as the error contains "com.company_name:lib_name:1.0.7-SNAPSHOT", the aforementioned is provided. you probably want to provide a different string.
    – EverNight
    Commented Aug 24, 2022 at 13:05
  • 1
    @EverNight I think OP just "obfuscated" the company/lib name, so there is no issue with this Commented Aug 25, 2022 at 15:18
  • @vladtkachuk maybe... but i think you're giving him too much credit ... i mean.... people usually mention "i've replaced actual lib names with fake ones", or "path_to_whatever"... + it'd take the kind of autism to make sure that all inconsequential -replaced text is correct across the entire posting that it just defeats the purpose ... so yeah... my money's on him not having obfuscated anything and just copy-pasting boilerplate code from somewhere without understanding much of what's going on
    – EverNight
    Commented Aug 25, 2022 at 15:38
  • Solved. All strings are fine, you probably misunderstood the problem. Issue was related to the VPN. Commented Aug 26, 2022 at 8:07
0

Solved. Issue was related to the VPN and got fixed in .github/workflows/sonar.yml:

name: SonarScan
on:
  pull_request:
  push:
    branches:
      - main # or the name of your main branch

jobs:
  build:
    name: SonarScan
    runs-on: ubuntu-latest <-- should be [self-hosted, main] to pass the wall
    steps:
      ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.