I'm looking to implement a pre-commit automatic formatter for my team because the code is a bit all over the place. I like spotless and the google style but a sticking point seems to be 4-space indents, whereas it's currently outputting 2-space indents.
Is there a way to override this value via pom.xml, either on spotless side or the google side?
As instructed in Github issue comments here: https://github.com/diffplug/spotless/issues/420
You can solve this in Gradle build with:
indentWithTabs(2)
indentWithSpaces(4)
For Maven the same code would be:
<java>
<googleJavaFormat>
<version>1.8</version>
<style>GOOGLE</style>
</googleJavaFormat>
<indent>
<tabs>true</tabs>
<spacesPerTab>2</spacesPerTab>
</indent>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</java>
Google java format is not configurable by design: https://github.com/google/google-java-format/pull/57#issuecomment-233450426
There is no configurability as to the formatter's algorithm for formatting. This is a deliberate design decision to unify our code formatting on a single format.
Also see: https://github.com/google/google-java-format/wiki/FAQ#i-just-need-to-configure-it-a-bit-differently-how
A quick update: the spotless plugin can now be configured to do what you want. I.e. google-java-format with 4 spaces.
As mentioned in the docs: https://github.com/diffplug/spotless/tree/main/plugin-maven
you can now use the AOSP 'style' which does what you need.
<googleJavaFormat>
<version>1.8</version>
<style>AOSP</style>
</googleJavaFormat>
Similar to the other answer, I tried to indent with Tabs(1) and Spaces(2). It also worked.
spotless {
java {
googleJavaFormat("1.7")
indentWithTabs(1)
indentWithSpaces(2)
}
}
Related
I am trying to configure the Cassandra code formatter and downloaded IntelliJ-codestyle.jar from this link: https://wiki.apache.org/cassandra/CodeStyle
After extracting this JAR, I was able to import codestyle/Default_1_.xml into my IntelliJ project and formatting seemed to work.
However, I'm wondering what options/code.style.schemes.xml file is exactly used for? Could anyone give me an idea the purpose of this file and how it should be used?
I didn't get the exact answer for the question, however, now I know how to set up the Cassandra project in IntelliJ such that the code formatter gets configured correctly:
The info is at this link:
https://github.com/apache/cassandra/blob/trunk/doc/source/development/ide.rst
I'm trying to use ANTLR3 task for Ant, but I get an "Unable to determine generated class" build failure message.
A quick research shows that many people have had the same problem, with no solution provided (see links below).
Can someone suggest a solution that doesn't resort to using a regular Java Ant task?
External links:
http://www.antlr.org/pipermail/antlr-interest/2009-November/036795.html
http://www.antlr.org/pipermail/antlr-interest/2006-July/016870.html
http://palove.kadeco.sk/itblog/posts/40
The antlr task included with Ant 1.8.2 (the latest version) seems to be dependent on ANTLR 2.7.2 (defined in $ANT_HOME/lib/ant-antlr.pom and using $ANT_HOME/lib/ant-antlr.jar.
What the task is doing is scanning the target file for a line matching ^class (.*) extends .*, where the first match group will be used as the name of the generated file. This whole bit of syntax seems to have been dropped in ANTLR 3.x, or at least made optional, because I'm able to generate parsers without it using the regular java task work-around you mentioned.
On the front page of http://antlr.org/ under the "File Sharing" heading is a link to ANTLR v3 task for Ant, but unfortunately it doesn't appear to be the sort of drop-in replacement I was hoping for. Actually, it seems to be rather convoluted so I've stuck with using the plain java task.
Is there a way to generate a latex document from my java sourcefile's documentation?
I don't want to include LaTeX Elements in my documentation comments, I simply want to create LaTeX files instead of HTML.
Thanks
An alternative to Texdoclet is the ltxdoclet I created.
I think the main difference is that it also includes the source code, not only the Javadoc comments, though you can switch this off.
It is not very well documented on the github site - just download the code and do ant pdfdoku for an example output (ant latexdoku if you only want the LaTeX files). (It is documented in german, though.)
I really should add a readme file there.
For now, here is the jar file - download it somewhere, and then use
javadoc -docletpath ltxdoclet.jar -doclet de.dclj.paul.ltxdoclet.DocletStart -help
to see a list of options available. (This will be in german, if you have no english locale. Prefix it with "LC_ALL=en_US" or similar on bash to get the english version, or have a look at help_en.txt instead if you don't know german.)
I'm working on a webpage with some more documentation, but I'm not sure when it will be ready.
Now we have a webpage, too. It links the jar file, and also as an example the javadocs when applied to itself.
Texdoclet seems to be what you need. As for how to use it: just like any other doclet.
If you don't want to rely on any doclet dependency, but rather on a javascript one, you can just add the following javadoc param:
-header "<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>"
and simply use clean latex inside your comments such as \(\sum_i a_i\) or \[\sum_i a_i\]
How can we generate javadoc as a word document instead of the traditional html pages?
look into doclets, http://doclet.com which have plenty of examples of custom javadoc rendering (i.e into PDF's etc...) and also look into Apache POI (http://poi.apache.org/) for the generation of MS Office files
If you could live with pdf instead of word, you should give PDFDoclet a chance. I discovered it on doclet.com (thanks to Mark for the link). It works quite well, is easy use and allows some configuration. For my purpose, pdf is better suited than word because a pdf document is better suited for reading than a word in regard to the needed viewer application.
Here is my small windows batch file:
echo OFF
set JAVA_HOME=C:/program files/Java/jdk1.6.0_23
set PATH=%JAVA_HOME%/bin;%PATH%
set VERSION=1.0.2
set DOCLET=com.tarsec.javadoc.pdfdoclet.PDFDoclet
set JARS=jar/pdfdoclet-%VERSION%-all.jar
set PACKAGE="cvu.html"
javadoc -doclet %DOCLET% -docletpath %JARS% -pdf html.pdf -config example/html/config_html.properties -private -sourcepath example/html -subpackges %PACKAGE%
http://doclet.com/ links an RTF Doclet ("RTF Doclet generates RTF format documentation.")
The resulting RTF opens in Word and Open Office Writer.
You can use maven to run the pdfdoclet. Though I did not find any "official" maven repository the following seems more clear to me, opposed to fiddling with shell scripts or using ant-commands in maven as proposed on their website:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<doclet>com.tarsec.javadoc.pdfdoclet.PDFDoclet</doclet>
<docletPath>path/to/pdfdoclet-1.0.2-all.jar</docletPath>
<useStandardDocletOptions>false</useStandardDocletOptions>
</configuration>
</plugin>
Note the disabling of the standard options, otherwise javadoc complains of unknown options (apparently not supported by the pdfdoclet)
From there you can start customizing, using the ever-concise maven documentation
Having just wrapped up a GWT-1.5 based project, I'm taking a look at what we'll have to do to migrate to 1.6. I'm very surprised to see that GWT seems to want to write its compiled output to the war directory, where you would normally have items under source control.
What's the reason behind this? Did Google really think this was a good idea? Is there a workaround to keep source code separate from compiler-generated artifacts? Is there some other reason for this that I'm missing?
EDIT:
It's been suggested that I use the -war option to specify an output directory. I wrote some ANT scripts, and have this mostly working. I've had to copy over my static resources such as HTML, JSPs, etc into this directory (I'm using target/war, maven-style). Is that what most people are doing? Or are you just letting GWT write its output into your source-code-controlled war dir, and telling your VCS to ignore the non-version-controlled files? It occurred to me that there might be some benefit to letting GWT write to this dir directly, since then Jetty could automatically notice changes to JSPs, HTML etc, and avoid having to do a copy to make these changes visible.
Use the "-war" option to control where the output goes.
FYI: The Wiki has the design doc which will, hopefully, give you a bit of insight as to what they were thinking.
See also the Release Notes which discuss the new project layout, as well as some things to watch out for with this change.
Salvador Diaz has provided an excellent solution to this.
Yep, look at the -war option which may help.
What I'm doing (which may not be as clean as maven, and I dont use the -war) is I'm putting my entire project dir on SVN, and then ignoring the subdir that holds the js and other compiled bs along with the classes dir. That way I have everything else on source control, including the libs which I wanted. So another team member can just check out the whole project from SVN, compile, and ready to go.