Sean Pianka
Sean Pianka

Reputation: 2325

Using Jenkins Shared Libraries, import Class from file within vars/?

I have two files:

Constants.groovy:

class Constants
{
    static String foo = "bar";
}

utils.groovy:

import Constants

void func()
{
    assert Constants.foo == "bar"
}

From within utils.groovy, I would like to import the Constants class. Here is the directory structure that the files reside within:

.
└── vars
    ├── Constants.groovy
    └── utils.groovy

This current setup does not work, and results in the following exception:

No such property: Constants for class: utils

Upvotes: 0

Views: 583

Answers (1)

Sean Pianka
Sean Pianka

Reputation: 2325

The solution is to append .* to the import:

import Constants.*

void func()
{
    assert Constants.foo == "bar"
}

I feel a bit silly, but the solution is simple!

Upvotes: 1

Related Questions