Cannot call the class from dynamic library

There is such a structure:

+- src                    
| +- org
|   +- foo
|     +- bar.groovy # different classes
+- vars
| +- foo.groovy # declarative pipelines
| +- baz.groovy # initializing pipelines

foo.groovy:

#!/usr/bin/env groovy

library retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://linkmygit.com/lib.git']),
        identifier: 'my-lib, changelog: false

import org.foo.*

def test = new Hello()
test.msg()

Bar.groovy:

package org.foo

class Hello {
    def test() {
        println("Hello World!")
    }
}

The library is downloaded, but the class can’t be called, it says it’s not found. I know this implementation is not suitable for a dynamic library, but I haven’t found any other options. I can’t use @Library(‘my lib’) because the library is in another repository.

Please tell me what other options are available?

do you wan to use the groovy @grab annotation to grab an external jar file?

why do you need to pull in stuff if its part of the structure already?

That’s not so. I am using pipeline script from scm. That is, I load the script from another jenkins space, so I need to load the library.

are you having a library in one pipeline trying to load a library from another pipeline?

I think you should move it all to an external shared pipeline that both use. I don’t think you can do it this way.

Not quite. We have a library that lies in some kind of repository and there are several projects in jenkins. There we create a job, where we indicate that we connect to our repository and take the necessary pipeline from vars. Ideally, we don’t want to store the pipeline in the project repository, but keep everything in one place.

So I’ll admit I’m not entirely sure what you are trying to do.

If i do understand you correctly, I still think shared pipelines is the way to go, instead of trying to load things from alternative locations.

For example, for my helm charts, my pipeline is just buildHelmChart() which maps to jenkins-shared-library/buildHelmChart.groovy at f2b30f61541b21f345b4677e29bba647e1e63da7 · halkeye/jenkins-shared-library · GitHub