I’m an old hand at c++ and nmake, but a newbie to gradle, trying to implement building my current java project. For that I need to build a java build tool to generate java files for the main application. My build tool has an external dependency.
For my minimal example I have this folder structure:
import org.apache.commons.cli.*;
public class buildTool {
public static void main(String[] args) throws IOException {
try {
CommandLineParser parser = new DefaultParser();
} catch (ParseException e) {
System.exit(1);
}
}
}
I’m using gradle 2.14.1 (though I get the same result with 3.0) and get:
Build file '/home/william/Documents/prj/sw/atarasec/grendel/code/buildSrc/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'buildSrc'.
> Could not find method apply() for arguments [{plugin=java}] on root project 'buildSrc' of type org.gradle.api.Project.
I’ve tried various permutations on the above source, but clearly I am missing something fundamental.
There are several issues with the minimal example, all of which are easily resolvable, but none of which should cause the error that you mentioned. If I fix these two issues, the minimal example provided runs correctly for me:
The buildSrc build.gradle needs a repositories declaration in order to resolve commons-cli.
The dependency declaration using map notation is missing the key for the first value (group).
Also, the error states that there is an issue with line 1 in buildSrc/build.gradle, but the message seems to reflect the contents of the root project build.gradle. Are you sure that this minimal example fails with the same error as your original project and that you accurately represented it here? It seems like something might be transposed. If you can’t tell what might different, pushing your minimal example exactly as you have it to GitHub might help.
Please keep in mind that the buildSrc project is a completely separate build. Nothing you do in your main build.gradle will have any effect on the buildSrc project.
Your suggestions plus fixing one other issue solved the problem.
The other issue was that somewhere along the line my build.gradle got saved as UTF8. So gradle was hitting the Byte Order Marker and failing. Saving build.gradle as ANSI fixed that!
Thanks. I’m still a little fuzzy when gradle ‘inherits’ build.gradle’s higher in the file tree. If I understand aright, if I were to run gradle within ./buildSrc, then it would ‘inherit’ the build.gradle in the root? (But of course that’s not what happens when you run gradle in the root, and gradle finds the magic folder ./buildSrc and does its thing.)