Not able to access classes in different packages from Job DSL scripts

615 views
Skip to first unread message

Ruhullah Shah

unread,
Dec 1, 2016, 10:47:20 AM12/1/16
to job-dsl-plugin
Hi,

I have the following project structure checked into ClearCase 

jobs/
   - Tests/
         TestDSL.groovy
   - Utils/
         Util.groovy

Util.groovy looks like
package Util

public class Util {
public static def sayHello() {
println "Hello"
}
}

TestDSL.groovy looks like
package Tests

import static Utils.Util.*

sayHello()
//dsl chopped off as it is irrelevant here

I get the following error on running TestDSL.groovy in Jenkins:
workspace:<path-to-project>/jobs/Tests/TestDSL.groovy: 2: unable to resolve class Utils.Util
 @ line 2, column 1.
   import static Utils.Util.*
   
1 error


Also my load rule is:

load <path-to-jobs>\jobs\Tests
Can I please get some suggestions to workaround this issue?

Thanks.

Victor Martinez

unread,
Dec 1, 2016, 12:50:35 PM12/1/16
to job-dsl-plugin
Couple of points:

- import Utils.* or import Utils.Util

- I dont think you need to set 'the Additional classpath' option in the Process Job DSLs build step pointing to the location of your class since that package is located in the root folder.

Cheers

Sai Kishore

unread,
Dec 1, 2016, 12:54:07 PM12/1/16
to job-dsl...@googlegroups.com

I hope we should use

Import static Utils.utils

Thanks
Sai kishore Amirishetty


--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/40de5051-d3a3-4156-b6f9-0b22887f44d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Dec 1, 2016, 1:25:40 PM12/1/16
to job-dsl-plugin
As far as i see there is a typho also in the package name and classname. Neither of them are not plurals,
packagename Util and className Util so therefore use
import <packageName>.<classname>


Victor Martinez

unread,
Dec 1, 2016, 1:25:41 PM12/1/16
to job-dsl-plugin

Ruhullah Shah

unread,
Dec 12, 2016, 7:22:16 AM12/12/16
to job-dsl-plugin
Hi Victor,

It was a copy-paste mistake and the name of the package is Utils.
Even with the correct name, I get the same error.

Thanks
Reply all
Reply to author
Forward
0 new messages