You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Oleksii Lomako (JIRA)" <ji...@apache.org> on 2019/05/29 10:19:00 UTC

[jira] [Created] (GROOVY-9150) Cannot use generated @Builder via static import

Oleksii Lomako created GROOVY-9150:
--------------------------------------

             Summary: Cannot use generated @Builder via static import
                 Key: GROOVY-9150
                 URL: https://issues.apache.org/jira/browse/GROOVY-9150
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.7
         Environment: Gradle:
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------

Build time:   2019-04-26 08:14:42 UTC
Revision:     261d171646b36a6a28d5a19a69676cd098a4c19d

Kotlin:       1.3.21
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_201 (Oracle Corporation 25.201-b09)
OS:           Mac OS X 10.14.5 x86_64

Spock: 1.3-groovy-2.5
Groovy: 2.5.7

            Reporter: Oleksii Lomako


It's not stated anywhere that it's impossible to use generated builder method via static import.

 

Given I have a Default Strategy builder, I expect I can import `aPerson` method to use in spock tests.
{code:java}
class PersonTestFactory {
    @Builder(builderMethodName = 'aPerson', buildMethodName = 'get')
    static Person personFactory(
            String name = 'John Doe',
            int age = 42,
            String gender = 'male'
    ) {
        return Person.builder()
                .name(name)
                .age(age)
                .gender(gender)
                .build()
    }
}
{code}
 

Getting this exception when running a spock test (not at compile time)
{code:java}
groovy.lang.MissingMethodException: No signature of method: test.PersonBuilderWithStarStaticImportSpec.aPerson() is applicable for argument types: () values: []
{code}
 

You can get a project with tests at [https://github.com/mutyonok/groovy-builder-static-import]

I've read about a similar problem with lombok generated code [here|https://github.com/rzwitserloot/lombok/wiki/LOMBOK-CONCEPT:-Resolution] and [here|https://github.com/rzwitserloot/lombok/issues/979] 

So would be good to clarify if it's the same issue or maybe groovy compiler can be smarter than javac.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)