2

I'm using IntelliJ Idea 2016.2.4 Community Edition and I have configured it so it autoformats my code (mostly Java or XML) when saving the file. This unfortunately includes that IntelliJ formats my license header (e.g. Apache license), which I create and validate via a Maven plugin com.mycila:license-maven-plugin.

How can I configure IntelliJ so that it does not reformat the license header?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
sascha_lamp
  • 179
  • 2
  • 12
  • Have you looked at http://stackoverflow.com/questions/3375307/how-to-disable-code-formatting-for-some-part-of-the-code-using-comments ? – belwood Dec 19 '16 at 22:28
  • I haven't, but this is not an option for me, since the license header check does not accept it. – sascha_lamp Dec 19 '16 at 22:55

1 Answers1

2

You can configure formatters but i'm not sure this is what you're looking for.Enable EditorConfig support Editor > Code Style. You need to add // @formatter:off at the beginning and // @formatter:on at the end of the ignored area.

Update: I've tested Apache License block at the very beginning of the Java source. And used single asterisks comment block instead of double asterisks(/**)
/* * * ... */
And Intellij is ignoring them and not touching to formatting at all.

Jama A.
  • 15,680
  • 10
  • 55
  • 88
  • Yeah, that does not format the header, but the Maven plugin to check for the license header does not accept this. I need the header to deploy/release my artifacts to Maven Central, and I suspect their validity check won't let it pass either. – sascha_lamp Dec 19 '16 at 22:46
  • Do you have single or double asterisks at the beginning of the license block? I verified if it's single it's not formatting them – Jama A. Dec 19 '16 at 22:56
  • It is generated with double asterisks. I can confirm it won't be formatted when using single asterisks but the Maven plugin does not accept it. – sascha_lamp Dec 19 '16 at 23:01
  • That's interesting I see single asterisks all over the codes from Apache. Ex: https://commons.apache.org/proper/commons-lang/apidocs/src-html/org/apache/commons/lang3/ArrayUtils.html – Jama A. Dec 19 '16 at 23:09
  • Yeah, it has already been issued: https://github.com/mycila/license-maven-plugin/issues/118 – sascha_lamp Dec 19 '16 at 23:14
  • ah that was a bug :) – Jama A. Dec 19 '16 at 23:15
  • Maybe I'll do a pull request then. It annoys me quite a lot although this plugin is pretty handy at all. Anyway thanks for the help. Haven't thought about using single asterisks. Was looking for a proper definition but couldn't find any. – sascha_lamp Dec 19 '16 at 23:19