converting an eclipse formatter file to a checkstyle file - maven

I have an eclipse formatting file (which contains some configurations) and i want to make the same thing (these configurations) for a checkstyle file to use after with maven build.

Unfortunately, there is no way to convert a formatter file to a checkstyle ruleset at the moment. You have to do it the other way around as explained here.
Otherwise you have to adjust every setting in your formatter manually for checkstyle.

The Eclipse-Checkstyle plugin provides an export feature to export your preferences.

Related

Can I have gradle support in IDEA without importing it?

I have quite big IDEA project which we incrementally migrate to gradle. I don't want to "import" newly migrated parts right now, but I do want to have IDEA support (syntax highlighting, code completion, etc) for writing gradle scripts. From brief searching it is still not obvious how to get it. Is it possible it all?
As long you have the Groovy plugin installed and enabled, and have *.gradle listed as a Registered Pattern for "Groovy" in Settings > Editor > File Types you should get groovy features when editing a build.gradle file.

Maven javadoc plugin how to exclude generated source

Some maven plugin can generate additional source code e.g., jaxb2.
I want to skip generating javadocs from target/generated-sources directory.
How to configure maven-javadoc-plugin to achieve this? Maybe there is some other way?
There is:
<sourceFileExcludes>
<sourceFileExclude>**/dir_name/*.java</sourceFileExclude>
</sourceFileExcludes>
I'm not sure if you can exclude based on directory, but you can use the <excludePackageNames> tag to exclude based on the package. (See documentation.) Does you autogenerated code all have the same Java package?
A simple and effective solution is to generate the code to a new package (for example: using ANTLR, move the grammars one layer deeper, from a your.package.here into a new your.package.here.antlr package).
Then, using Andrew Rueckert's suggestion, add <excludePackageNames>*.antlr</excludePackageNames> in the maven javadoc plugin configuration in your pom file.
And another possible solution is to set <sourceFileIncludes>, e.g:
<sourceFileIncludes>**/com/pany/different/package/**/*.java</sourceFileIncludes>
Works only if your main source dirs ends differently from generated sources.

How fix all check style issues with Intellij Idea?

I have an xml configuration file for maven checkstyle plugin. I have installed Intellij Idea plugin and see all checkstyle violation. Is there a way to fix most of them automatically? For example auto formatting setting? Is there a way to setup Intellij Idea to autoformat from checktyle config file?
There is an option now.
checkstyle-IDEA since 4.24.0 features import of checkstyle config.
Please install CheckStyle-IDEA plugin
(http://plugins.jetbrains.com/plugin/1065?pr=idea), it can be found
via plug-in repository (Settings|Plugins|Browse repositories). Go to
Settings|Editor|Code Style, choose a code style you want to import
CheckStyle configuration to. Click on the gear, then 'import scheme', choose
"CheckStyle Configuration" and select a corresponding CheckStyle
configuration file. Click OK. At the end you will see a message
"CheckStyle configuration settings were imported to ... scheme".
If you encounter any problems, you can create a new issue for the
CheckStyle plug-in here:
https://github.com/jshiell/checkstyle-idea/issues. This issue is
actually a duplicate of
https://github.com/jshiell/checkstyle-idea/issues/126.
CheckStyle plug-in version where the feature is available is 4.24.0
Copied from https://youtrack.jetbrains.com/issue/IDEA-61520#comment=27-1292600. Copied the answer from here
Edit: Quote has been changed for clarity and to meet the current UI design.
I have the same problem. As far as I know, the rules used for reformatting cannot be imported from Checkstyle config. You can configure your Checkstyle rules in the Idea's Code Style config (File -> Settings -> Code Style) and then reformat the code (Code -> Reformat Code [Ctrl+Alt+L]) according to the rules (you can apply it to the whole code base at once).
import your code style config first
reformat your code.

how to make checkstyle ignore xml files in my application

i've configured my checkstyle plugin with customized checkstyle.xml and it works fine with the java classes but having a lot of warnings with the xml files can anyone suggest how to disable the check style from any xml file in my application.
thanks in advance.
I can think of two ways to do that:
You could suppress findings from non-Java files. This works very well inside and outside of your IDE.
If you are using Eclipse, you can also configure Eclipse not to feed the non-Java files to Checkstyle. In order to do that, right-click your project and click Checkstyle. Uncheck use simple configuration. Specify a file set using \.java$ as regexp. You will see the list of files in the bottom half of the dialog window change to only Java files.
In earlier versions of Checkstyle, I think I remember that there also was a file name filter in the configuration XML, but I can't seem to find it in the docs now, so maybe that feature is no more.
There is a basedir property at the start of the Checker module in the check style config file. Uncomment it if it is commented.
Set it's value to the folder you want to apply your checkstyle rules to.
E.g. src folder of any eclipse project only contains java files.
<!-- If you set the basedir property below, then all reported file names
will be relative to the specified directory. See http://checkstyle.sourceforge.net/5.x/config.html#Checker -->
<property name="basedir" value="/MyEclipeProject/src"/>

How to use auto_import feature with FreeMarker and maven or ant (not servlet)

I'd like to test using freemarker to automatically build my html files at compile time (not use the servlet) and want to use the auto_import feature so I don't have to re define the template for each file. I can either use ANT or Maven. How do you use the auto_import feature to automatically load templates within FreeMarker using either ANT or Maven?
auto_imports is just one of the many FreeMarker settings, and it has nothing to do with servlets, Maven or Ant. So if you can process the files with Ant or Maven (one way is using the Maven FMPP plugin or the Ant FMPP task), then you should be able to use use auto_imports as well.
Update: There's an issue with FMPP (until 0.9.15 is released): it doesn't know this setting, so you can't set it through FMPP. But instead it has "Header and footer choosing", which is even more flexible. See: http://fmpp.sourceforge.net/settings.html
Have you tried FMPP?
FMPP is a general-purpose text file preprocessor tool that uses FreeMarker templates.
It can be used via command-line or Ant and might provide all the features you need.

Resources