Everything I have seen and read would indicate this is correct, and my unit test for a thrown exception when projectFile isn’t set also passes. However, when I step through the code in debug mode I can see the values are null, and when I compile and try running the project in a test build, it fails. Ignoring the duff unit tests for a moment, is there anything strikingly obvious that I’m doing wrong?
having it like this will not work (object will be null):
class SoapUIPluginExtension {
SoapUIToolConvention tool
SoapUISecurityConvention security
SoapUILoadConvention load
SoapUITestConvention test
SoapUIMockConvention mock
}
this will also not work (properties of these objects will be null):
class SoapUIPluginExtension {
SoapUIToolConvention tool = new SoapUIToolConvention()
SoapUISecurityConvention security = new SoapUISecurityConvention()
SoapUILoadConvention load = new SoapUILoadConvention()
SoapUITestConvention test = new SoapUITestConvention()
SoapUIMockConvention mock = new SoapUIMockConvention()
}
Smells like a bug or at least there is room for improvement: - maybe add an “Extension”-Annotation and then automatically initialize nested extensions - at least warn if People try to use the 2nd or 3rd Version of the Extension class (shadowing the actual nested-extensions with null objects or uninitalized Extension objects)
I was sincerely hoping this would work but still no satisfaction.
:soaptest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':soaptest'.
> soapui-project-file setting is required
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.855 secs
When I run my test that ive now added to the project I get the error above
Convention mapping only works if the getter is called. Groovy automatically calls the getter if you use > property syntax, except when the property is declared in the same class.
so when you change your code from
if (!projectFile) {
new GradleException('soapui-project-file setting is required')
}
to
if (!getProjectFile()) {
new GradleException('soapui-project-file setting is required')
}
it works. This is needed since the projectFile property is defined in the same class and groovy will not call the conventionMapinng-getter.
Of course this has to be done in all methods of classes that rely on convention mapping and currently use properties directly without the getter.
result:
:soaptest (Thread[main,5,main]) started.
:soaptest
Executing task ':soaptest' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
:soaptest (Thread[main,5,main]) completed. Took 0.018 secs.
BUILD SUCCESSFUL
Total time: 2.503 secs