[JAVA] [Gradle] [checkstyle] What to do if the active setting of Checkstyle is removed by "Refresh Gradle project" from Eclipse

I referred to this site. http://irtakt.hatenablog.com/entry/2014/05/04/233312

It seems that it may or may not occur depending on the environment. I checked Checkstyle ⇒ "Activate Checkstyle in this project" in the project properties of Eclipse, but This is a workaround when the check is unchecked when "Refresh Gradle project" [^ ref] is executed.

image.png

image.png

And the check is unchecked

Cause

The cause is that gradle's eclipse plugin is called in "Refresh Gradle project", This is because the ".project" file will be rebuilt and Checkstyle's buildCommand and nature will be out of sync.

http://gradle.monochromeroad.com/docs/userguide/eclipse_plugin.html

Coping

Add the following description to the build.gradle file.

build.gradle


apply plugin: 'eclipse'

eclipse {
    project {
        natures 'net.sf.eclipsecs.core.CheckstyleNature'
        buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
    }
}

Now, when you "Refresh Gradle project" [^ ref], the buildCommand and nature for Checkstyle will be described in the ".project" file, and you can always turn on the Checkstyle active setting of Eclipse.

Below is the created ".project" file

.project


<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<!--・ ・ ・ ・-->
	<buildSpec>
		<!--・ ・ ・ ・-->
		<buildCommand>
			<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<!--・ ・ ・ ・-->
	</buildSpec>
	<natures>
		<!--・ ・ ・ ・-->
		<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
		<!--・ ・ ・ ・-->
	</natures>
</projectDescription>

[^ ref]: Or run gradle eclipse.

Recommended Posts

[Gradle] [checkstyle] What to do if the active setting of Checkstyle is removed by "Refresh Gradle project" from Eclipse
What to do if the Eclipse Maven dependency Jar is wrong
[Ubuntu 20.04] What to do if the external monitor is not recognized
What to do if Cloud9 is full in the Rails tutorial
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible
What to do if the prefix c is not bound in JSP
What to do if you don't like the code generated by swagger-codegen-cli
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do if the image posted by refile disappears after setting a 404 error page in Rails
[Rails / Docker] What to do if access is denied by the browser (localhost: 3000) after adding a gem
What to do if the server tomcat dies
What to do if Command line is too long appears when building a gradle project in Intellij IDEA
[Swift] What to do if the app icon is set but not reflected
What to do if you can't get the text of an element in Selenium
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
What to do if the breakpoint is shaded and does not stop during debugging
When the hover of Eclipse is hard to see
What to do if the debug gem installation fails
What to do if the Rails server can't start
The story of migrating from Paperclip to Active Storage
What to do if you change the Listen Address from the settings screen with Mattermost docker
What to do if audio is not available on discordrb
What to do if FacesMessage is set but not displayed
[Java] What to do if a lot of "File is opened too much" is displayed due to FileNotFoundException
What to do if the app is not created with the latest Rails version installed when rails new
What to do if validation doesn't work with the update action
[Rails] What to do if data is not registered in DB
Want to know what Ruby n is the power of 2? (Power judgment of 2)
If you want to change the Java development environment from Eclipse
What to do if Operation not permitted is displayed when you execute a command in the terminal
'% 02d' What is the percentage of% 2?
[IOS] What to do when the image is filled with one color
Get the type of an array element to determine if it is an array
From Java9, the constructor of the class corresponding to primitive types is deprecated.
What to do if the build fails with the error "Module compiled with Swift x.x.x cannot be imported by the Swift x.x.x compiler"
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if you get Could not save master table to file after importing a project in Eclipse