0

I am working on a Java project which uses MapStruct. We would like the SonarQube Java rule engine's rule "Public types, methods and fields (API) should be documented with Javadoc" to be ignored for method declarations in MapStruct's mappers, because they are self-explanatory and there is a lot of them, so it is making the sonar's issues a mess.

Is there a way to do that? I can't find any answers, but I can't imagine everyone else is typing meaningless Javadocs to fulfil the rule.

5
  • 1
    Hi Jarmila, I think you can achieve this using the sonar-project.properties file like here: stackoverflow.com/a/65340805/3154883 Commented Jan 11, 2021 at 12:24
  • Have you tried to apply @SuppressWarnings( "javadoc" ) to the respective class or to each element that lacks the documentation? I do not know SonarQube, so I do not know whether it honours the annotation, but it may be worth a try. Commented Jan 11, 2021 at 12:34
  • Hi @Brother, thank you for the tip. I'll have look at it. tquadrat thank you, I also ran into this possibility used in different cases when I was googling and I gave it a try but it did not work :\ Commented Jan 11, 2021 at 12:43
  • @tquadrat I've found out that instead of @SuppressWarnings("javadoc"), which does not work, I can use @SuppressWarnings("squid:S1176") which works. But I have to annotate all the methods or at least all the "mapper" interfaces which they are in. That does not seem elegant though. It would be great if I could somehow use the annotation in the MapStructGlobalConfig and it was then applied to all the mapper methods. I've experimented with it a little but I didn't manage to make it work. Commented Jan 11, 2021 at 15:58
  • @Brother It seems like with the sonar-project.properties I can only exclude whole files so that the specified rules are not being applied on them. We tend to keep the mapper interface in one file along with the class that calls the mapping methods, so I would have to exclude more code than I need to or change the convention in our projects. Commented Jan 11, 2021 at 16:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.