I am using Java EE with Maven.
For readability and easy checks, I want to use Groovy’s PowerAssert in production code.
Is there a way of doing this in standard Java classes?
I tried adding the ‘groovy-all’ package as Maven dependency, but the following code fails. What should I import?
public static void main(String[] args) {
assert (2 + 2 == 5, "Surprise: this assertion failed!");
}
I’m assuming you mean the code fails to compile, but correct me if I’m wrong. You’re not going to be able to use Groovy-only syntax in your Java classes, I’m afraid. The guts of groovy for this functionality seem interwoven with Groovy compilation, if a quick look is correct, so I don’t think it’s really hackable for your java code. For areas of code where you want groovy functionality, perhaps you can embed scripts.