How to enable linebreak between license header and delimiter
we are using maven (3.8.6+) and spotless maven plugin 2.33.0
The configuration looks like
<configuration>
<java>
<googleJavaFormat>
<version>1.15.0</version>
<style>AOSP</style>
</googleJavaFormat>
...
<licenseHeader>
<content>${spotless.license.header}</content>
<delimiter>${spotless.delimiter}</delimiter>
</licenseHeader>
</java>
</configuration>
Where ${spotless.delimiter} is just package
The problem is that
after applying it looks like
// LICENSE
package ...
and we want to have a line break between the license and package
like
// LICENSE
package ...
an attempt to insert extra line breaks into LICENSE doesn't help. Is there a way to make it possible?
Can you please share your code where you've defined spotless.license.header
Also, have you tried using custom FormatExtension? I think you should have a separate custom FormatExtesion to do the needful
Here it is an example https://github.com/datafaker-net/datafaker/blob/ba65ca925835a1834010bae7c4c36e09ef1d94db/pom.xml#L242-L253
and the definition of spotless.license.header https://github.com/datafaker-net/datafaker/blob/ba65ca925835a1834010bae7c4c36e09ef1d94db/pom.xml#L58-L60
I think it might be because the XML parsing is trimming "meaningless" trailing newlines. If you specify a license file instead of an inline constant, then it should respect the newline.
Why was this closed? Using a license file is a workaround, not a solution. The default behavior here for license generation actually breaks a Checkstyle default code smell for "'package' should be separate from previous line".
To the best of my knowledge, this is a limitation of XML, there is no way to have significant trailing whitespace. So the workaround is the best we can do. Happy to merge a PR that fixes this some other way, but I am betting against such a PR being possible.
What about using CDATA and \n?
https://www.w3.org/TR/REC-xml/#sec-cdata-sect
I would argue that the extra newline should be added by default. And/or perhaps adding a new option to include an extra newline?
<licenseHeader> <!-- specify either content or file, but not both -->
<content>/* (C)$YEAR */</content> <!-- or <file>${project.basedir}/license-header</file> -->
<delimiter>#</delimiter> <!-- content until first occurrence of the delimiter regex will be interpreted as header section -->
<extraNewline>true</extraNewline> <!-- always include an extra newline between header section and delimiter -->
</licenseHeader>
``
I would argue that the extra newline should be added by default.
Perhaps, but we aren't going to make a breaking change for this.
What about using CDATA and \n?
Seems like that would work, good idea! That should probably be the real answer.
perhaps adding a new option to include an extra newline?
My #1 goal is to help people enforce whatever rules they want, my #2 rule is to maintain as few features as possible to make that possible. We have at least 1, possibly 2 (if CDATA works) solutions to this problem. They use the public API in exactly the way it is meant to be used, so I don't think they are "workarounds".
If you really want extraNewline and you can do it inside the Maven DSL without changing the LicenseHeaderStep itself, I would probably merge it. Adds 1 line to the docs, maybe 20 lines to the code? Doesn't seem like a good use of time to me, but sure. If it ends up being like 100 lines then no way, use the workarounds.