[JAVA] Tips for generating files for eclipse projects in Gradle

Tips for settings to be added to build.grade when generating an eclipse project using gradle. For myself. These settings can be set from the IDE after creating an eclipse project file with gradle, but it is troublesome to do each time, so I wanted to put it in build.gradle.

Pull the path out of the .classpath file

If you create an eclipse project with a specific module (specifically DynamoDBLocal) set as a dependency of gradle, .so and .dll will be included in the classpath, so the eclipse project will fail. In this case, exclude the path from the file generated as follows.

eclipse.classpath.file {
    whenMerged { classpath ->
        classpath.entries.removeAll { entry -> (entry.path.endsWith('dll') || entry.path.endsWith('so') || entry.path.endsWith('dylib')) }
    }
}

Add to JRE default access rules

Certain packages (specifically javafx and javax.smartcardio) are hidden from eclipse by default and result in an error. In this case, add it to the JRE access rule as follows.

eclipse.classpath.file {
    whenMerged {
        def jre_container = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
        jre_container.accessRules << new org.gradle.plugins.ide.eclipse.model.AccessRule("accessible", "javax/smartcardio/**")        
    }
}

Add Project Nature

Certain Project Nature (specifically gradle and STS Gradle plugins) is not set by default. In this case, add project nature as follows

eclipse.project {
    buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
    natures 'org.eclipse.buildship.core.gradleprojectnature'
}

Also, in the case of Buildship, an error will occur if there is no pref file under .settings, so create the file as follows.

tasks.eclipse.doFirst {
	File prefs = file(".settings/org.eclipse.buildship.core.prefs")
	if(!prefs.exists()){
    	prefs.append('''
			connection.project.dir=
			eclipse.preferences.version=1
    		'''.stripIndent())
	}
}

Note that these settings seem to work well if you already have various configuration files.

gradle cleanEclipse eclipse

It seems better to clean the eclipse project file once.

Referenced entry:

Recommended Posts

Tips for generating files for eclipse projects in Gradle
Gradle TIPS collection (for myself)
Tips for handling enums in thymeleaf
Tips for handling pseudo-elements in Selenium
Enable code completion in Eclipse for Mac
Tips for gRPC error handling in Ruby
[For beginners] How to debug in Eclipse
Eclipse Pleiades All in One for Mac released
Technology for reading Java source code in Eclipse
[Gradle] Build operations often performed in Java projects
Prepare for log output using log4j in Eclipse.
Resolve "Cannot resolve symbol" in IntelliJ projects using Gradle
[Note] Struts2 environment construction using Gradle in Eclipse
tips for java.nio.file.Path
My Eclipse Tips
MVC in Eclipse.
Tips for setting the initial delay for Poller in XML
Tips for making good use of Canvas in Xcode