Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for project Lombok #182

Closed
geekmj opened this issue Oct 13, 2015 · 23 comments
Closed

Support for project Lombok #182

geekmj opened this issue Oct 13, 2015 · 23 comments
Milestone

Comments

@geekmj
Copy link

geekmj commented Oct 13, 2015

I am seeing enuciate is not generating no attributes for data type if project is using Lombok.

Using Lombok we don't need to explicit getter and setter code.

I am using gradle enuciate plugin.

@stoicflame
Copy link
Owner

Acknowledged. I'll make this an enhancement request for support for project Lombok.

@stoicflame stoicflame changed the title No Attributes in generated Data Type when using Lombok Support for project Lombok Oct 13, 2015
@scoquelin
Copy link

+1 for Lombok support !

@stoicflame stoicflame added this to the v2.1.0 milestone Oct 30, 2015
@stoicflame
Copy link
Owner

Okay, so I'm having a hard time figuring out how to integrate with Lombok. My goal is to get Enunciate to be compiled against the code generated by Lombok, but the project homepage seems to imply that it's integrated into the IDE.

How does it work? If you're using Gradle, does Gradle use some kind of Lombok task to generate the boilerplate code? Or you do you rely on Eclipse to generate the boilerplate code and then have Gradle compile it that way?

@stoicflame stoicflame removed this from the v2.1.0 milestone Nov 2, 2015
@scoquelin
Copy link

Hi @stoicflame the project homepage gives instructions to "patch" your IDE to properly handle lombok annotations but to generate code using lombok you just need to include lombok dependency in your pom.xml or build.gradle and put lombok annotations in your code! You can find more here : http://jnb.ociweb.com/jnb/jnbJan2010.html
Hope that helps !

@stoicflame
Copy link
Owner

Does anyone have a sample project I can use to demonstrate how to apply Enunciate to it?

@scoquelin
Copy link

Today I took the enunciate-sample project and lombokized it!
https://github.com/scoquelin/enunciate-sample/tree/enunciate-sample-lombok

The good news is that - overall - it is working for me !

However, I am actually running into issues with @Builder annotations when I explicitly add :
import com.ifyouwannabecool.domain.persona.Persona.PersonaBuilder;
to make use of it directly instead of using Persona.PersonaBuilder

See :
scoquelin/enunciate-sample@enunciate-sample-lombok...scoquelin:enunciate-sample-lombok-failing

In that case I get :

[WARNING] [ENUNCIATE] [javac] [ERROR] com.webcohesion.enunciate.Enunciate$URLFileObject[file:/home/seb/git/enunciate-sample/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java]:6:51 /home/seb/git/enunciate-sample/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java:6: error: cannot find symbol
[WARNING] [ENUNCIATE] [javac] /home/seb/git/enunciate-sample/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java:6: error: cannot find symbol
[WARNING] [ENUNCIATE] [javac] import com.ifyouwannabecool.domain.persona.Persona.PersonaBuilder;
[WARNING] [ENUNCIATE] [javac]                                                   ^
[WARNING] [ENUNCIATE] [javac]   symbol:   class PersonaBuilder
[WARNING] [ENUNCIATE] [javac]   location: class com.ifyouwannabecool.domain.persona.Persona

and I'm not sure if we can relate that one to any existing issue...

On my end I will see if I can workaround the issue in my own project by always using Persona.PersonaBuilder to make a reference to the builder, will keep you up-to-date.

@scoquelin
Copy link

After using the workaround above and also after removing duplicate class name reported in #166 I'm now able to generate enunciate docs for my project! Thanks a lot @stoicflame for the great work! I think you can safely close that issue as it was confirmed (using branch listed above) that using lombok works with enunciate without any major issue.

@stoicflame
Copy link
Owner

Sweet. Thanks!

@gaetancollaud
Copy link

This issue is closed, but there is no milestone specified. Does enunciate 2.2.0 support lombok or will it be for the next release ? I tried the 2.2.0 but it doesn't work for me. Maybe I miss something but it works if I manually write the getters.

@stoicflame
Copy link
Owner

This issue is closed because support can be enabled by using the technique described above.

@nabilzhang
Copy link

nabilzhang commented Jun 14, 2016

I think should use like this

        <plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.16.8.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>delombok</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <addOutputDirectory>false</addOutputDirectory>
                    <sourceDirectory>src/main/java</sourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>```

then
```<reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <aggregate>true</aggregate>
                    <defaultVersion>${project.version}</defaultVersion>

                    <sourcepath>${project.build.directory}/generated-sources/delombok</sourcepath>

                </configuration>
            </plugin>
        </plugins>
    </reporting>

maybe like java doc plugin, should surpport like sourcepath config

@stoicflame
Copy link
Owner

Seems reasonable.

Tracking at #427.

@markozi
Copy link

markozi commented Jun 16, 2016

I have tried the solution proposed above but still find unsufficient support. In the enunciate-sample-lombok there is no Javadoc on the model fields. Even when I add Javadoc to the Persona fields, I can't find no documentation on the enunciate html page. In fact, there is no field at all and the example says <persona/>. It seems like enunciate only produces descriptions for public getter methods, but not for private fields for which lombok creates getters and setters.
It would be nice if either enunciate takes the Javadoc from the private fields or lombok copies the Javadoc to the getters and setters it generates (provided that enunciate hooks into the process after lombok and sees its changes).

@stoicflame
Copy link
Owner

I'll take a closer look at Lombok support for 2.6.

@stoicflame
Copy link
Owner

Okay, with the fix at #427, I was able to successfully integrate Enunciate into a Lombok project as follows:

Configure Lombok to Generate the Sources

In Maven, it looks like this:

      <plugin>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-maven-plugin</artifactId>
        <version>${lombok.version}</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>delombok</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <encoding>utf-8</encoding>
          <addOutputDirectory>false</addOutputDirectory>
          <sourceDirectory>src/main/java</sourceDirectory>
        </configuration>
      </plugin>

The Lombok plugin will put the generated sources in ${project.build.directory}/generated-sources/delombok.

Set the Enunciate Compiler Directory

In Maven, that looks like this:

      <plugin>
        <groupId>com.webcohesion.enunciate</groupId>
        <artifactId>enunciate-maven-plugin</artifactId>
        <version>${enunciate.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>assemble</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources/delombok</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

I have confirmed that the appropriate documentation is also included.

@gaetancollaud
Copy link

Great news ! I'm looking forward for the 2.6.0 then.

@stoicflame
Copy link
Owner

@SpOOnman
Copy link
Contributor

How about gradle? I'm not able to create it with gradle plugin. Even with uncommented sourcepath metod I still get empty classes with no properties.

import io.franzbecker.gradle.lombok.task.DelombokTask
task delombok(type: DelombokTask) {
    args("src/main/java", "-d", "build/delombok/src/main/java")
}

tasks.enunciate {
  File enunciateDistDir = file("dist/docs/api")
  doFirst {
    enunciateDistDir.deleteDir()
    enunciateDistDir.mkdirs()
  }
//  sourcepath(file("build/delombok"))
  export("docs", enunciateDistDir)
}

@SpOOnman
Copy link
Contributor

I don't know Enunciate internals, but maybe it is worth to create lombok module to first-class support instead of using delombok step? Would it be doable @stoicflame ?

@stoicflame
Copy link
Owner

We may need to enhance the gradle plugin to support setting the source files.

Sure, a lombok module is totally doable.

@stoicflame
Copy link
Owner

At 43a3ca0, @SpOOnman contributed a new module with native Lombok support, so you don't have to apply the delombok step. This will be included in Enunciate 2.7.

See https://github.com/stoicflame/enunciate/wiki/Lombok.

@peter-janssen
Copy link
Contributor

peter-janssen commented Nov 9, 2016

@stoicflame For some strange reason I can't get lombok support working. After running the archetype I've changed the pom according to the wiki. And I added @Getter and @Setter to both Persona.class and Name.class and removed all getter and setter methods. After running maven the parameters are no longer shown in the Json nor xml datatypes. They are also no longer present in swagger.
I also tried the jackson2-api-lombok example. This works out of the box (tag v2.7.0) but I noticed the getter and setter methods in for example Name.class and Person.class are still present. After removing these (in the case of Person only for id) these are also no longer present in the docs. What am I missing here?

@stoicflame
Copy link
Owner

@peter-janssen, I'm not seeing the problem. When I remove the getId and setId methods on Person in the jackson2-api-lombok, the property still shows up.

See this patch.

If you can provide more details about what you're seeing, let's open a new issue to track it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants