When I run my Groovy script via the command-line or Jenkins, I am getting an "unable to resolve class" error.
I have the following 2 groovy files within the same folder in C:\Users\myuser\git\productname\mycompany-build\src\main\groovy\com\mycompany\build
Foo.groovy
package com.mycompany.build
class Foo {
Foo() {
}
public void runBar() {
Bar bar = new Bar();
bar.name = "my name";
System.out.println(bar.name);
}
static void main(String[] args) {
Foo foo = new Foo();
foo.runBar()
}
}
Bar.groovy
package com.mycompany.build
class Bar {
String name;
}
I run Foo.groovy using the command-line.
I am located within the following directory when I run Groovy:
C:\Users\myuser\git\productname\mycompany-build\src\main\groovy\com\mycompany\build
This is what I enter on the command-line (cmd):
C:/java/tools/groovy-2.4.11/bin/groovy -cp C:/Users/myuser/git/myproject/mycompany-build/src/main/groovy/com/mycompany/build Foo.groovy
I get the following where it is unable to find the class "Bar", but the Bar.groovy file is in the same directory as Foo.groovy, not to mention that I do specify the -cp as well.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Users\myuser\git\myproject\mycompany-build\src\main\groovy\com\mycompany\build\Foo.groovy: 9: unable to resolve class Bar
@ line 9, column 9.
Bar bar = new Bar();
^
C:\Users\myuser\git\myproject\mycompany-build\src\main\groovy\com\mycompany\build\Foo.groovy: 9: unable to resolve class Bar
@ line 9, column 15.
Bar bar = new Bar();
^
2 errors
Can you please advise on how I can get this running from the command-line?
Once I am able to get this running, I plan to run this within a Jenkins job. I started off attempting to run this within a Jenkins job, but got the same issue which led me to look at running it off the command-line first.
I did attempt this with forward-slashes and back-slashes, but with no difference in behaviour.