Home > Net >  How to import from one level above the current package in groovy - elaboration
How to import from one level above the current package in groovy - elaboration

Time:10-14

I have a very similar issue to what is described here: How to import from one level above the current package in groovy

I don't want to move SharedState to an action/pkg subdirectory. What I want to do is to maintain the following structure:

  • groovy / action / TestDataHelper
  • groovy / action2 / TestDataHelper2
  • groovy / action3 / SharedState

and then gain access to SharedState from both TestDataHelper and TestDataHelper2.

I cannot do that anyhow using package, which I tend to understand is impossible by default. I could use classpath shenanigans instead, but need some guidance on that first.

Thanks for any kind of feedback.

CodePudding user response:

The answer is to use additional class path in the Jenkins job seed job - advanced section in the Build. The path needs to be matching mother directory of the project.

/home/user/mother_dir

The groovy script can be anywhere under /home/user/mother_dir, in my case it's under /home/user/mother_dir/other_dir/script.groovy

Then, I put the classes I would like to import within a package in a /home/user/mother_dir/package_dir. In the groovy script mapped with the job I import package.* and have access to all the necessary classes from the package_dir.

  • Related