Skip to content

Commit 51cde82

Browse files
committed
Merge pull request #266 from ttddyy
* pr/266: Polish 'Add instruction to setup code in IntelliJ IDEA' Add instruction to setup code in IntelliJ IDEA Closes gh-266
2 parents e27db53 + 66d8af1 commit 51cde82

6 files changed

+116
-1
lines changed
455 KB
Loading

.github/images/setup-idea-library.png

350 KB
Loading
345 KB
Loading
609 KB
Loading

CONTRIBUTING.adoc

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ should also work without issue.
2929

3030

3131
=== Building From Source
32-
To build the source you will need to install JDK 1.8.
32+
To build the source you will need to install JDK 11.
3333

3434

3535

@@ -60,6 +60,112 @@ NOTE: You'll need to close the `spring-javaformat-formatter-eclipse` and `spring
6060

6161

6262

63+
=== Importing Into IntelliJ IDEA
64+
You can import the code as a maven project into IntelliJ IDEA.
65+
66+
67+
68+
==== Module Dependencies
69+
When IntelliJ IDEA parses `pom.xml`, it automatically creates inter-module dependencies if dependent libraries are coming from other modules within the project.
70+
However, when dependent modules perform repackaging (e.g. `spring-javaformat-formatter-eclipse-runtime` module), the current module cannot resolve all classes by module dependencies because repackaging (shade & binary manipulation) moves around classes.
71+
Therefore, you need to manually update the dependencies from the module to the produced jars.
72+
73+
Following modules perform repackaging.
74+
75+
* `spring-javaformat-formatter-eclipse`
76+
* `spring-javaformat-formatter-eclipse-runtime`
77+
78+
Modules that depend on these modules need jar dependencies instead of module dependencies.
79+
80+
81+
82+
===== Setting up Jar Dependencies
83+
The following steps define jar-based project libraries on IDE and add them to the modules that need jar dependencies.
84+
85+
*Add a jar file-based project library*
86+
87+
* "Project Settings" -> "Libraries"
88+
* Click "+" sign, then select "Java"
89+
* Specify the jar file
90+
91+
For example, you can specify the jar file in the target directory(`<PROJECT>/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/target/spring-javaformat-formatter-eclipse-runtime-0.0.28-SNAPSHOT.jar`)
92+
or one in the local maven repository(`~/.m2/repository/io/spring/javaformat/spring-javaformat-formatter-eclipse-runtime/0.0.28-SNAPSHOT/spring-javaformat-formatter-eclipse-runtime-0.0.28-SNAPSHOT.jar`).
93+
94+
image::.github/images/setup-idea-library.png[Setup IntelliJ IDEA library]
95+
96+
*Add library dependencies to modules*
97+
98+
* "Project Settings" -> "Modules"
99+
* Select a module that depends on repackaging modules
100+
* Click "+" sign and "2 Library"
101+
* "Choose Libraries" and select necessary libraries that have added in the previous step
102+
* Move up the added libraries higher than the module dependencies (or remove the module dependencies)
103+
104+
image::.github/images/setup-idea-dependency.png[Setup IntelliJ IDEA Dependencies]
105+
106+
107+
108+
=== Setting up IntelliJ IDEA Plugin Development
109+
110+
111+
==== Download Images
112+
To develop the `spring-javaformat-intellij-idea-plugin` module, you need an IntelliJ IDEA application on your local machine.
113+
114+
* Open the `pom.xml` in `spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-runtime`.
115+
* Check `intellij.binary` and `intellij.source` properties to find out the appropriate IntelliJ IDEA version.
116+
* Download the binary from the url in `intellij.binary`.
117+
(For OSX, replace the `.tar.gz` to `.dmg` to download the image file.)
118+
* Install the image to the local machine
119+
* Download the source files from github specified in `intellij.source` and unzip it.
120+
121+
122+
123+
==== Setup SDK
124+
* Open "Project Structure" - "Platform Settings" - "SDKs"
125+
* Click "+" sign, "Add Intellij Platform Plugin SDK..."
126+
* Specify the installed intellij image. (`/applications/IntelliJ IDEA CE` for OSX)
127+
* On the right panel, "Sourcepath", Click "+" sign, specify unzipped intellij source directory
128+
* Specify "Sandbox Home" directory
129+
130+
image::.github/images/setup-idea-plugin-sdk.png[Setup IntelliJ IDEA Plugin SDK]
131+
132+
Please see the https://plugins.jetbrains.com/docs/intellij/setting-up-environment.html[IntelliJ IDEA reference] for how to setup a plugin development in details.
133+
134+
135+
136+
==== Convert to Plugin Module
137+
The imported `spring-javaformat-intellij-idea-plugin` module is recognized as a java module.
138+
This needs to be converted to a plugin module.
139+
140+
* Open `spring-javaformat-intellij-idea-plugin.iml` in `spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin`
141+
* Change `type="JAVA_MODULE"` to `type="PLUGIN_MODULE"`
142+
143+
[source,xml]
144+
----
145+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="PLUGIN_MODULE" version="4">
146+
----
147+
148+
Reference https://stackoverflow.com/questions/18278440/how-to-import-and-run-existing-plugins-from-intellij-community-edition-repo[how to convert existing module to a plugin module]
149+
150+
* Open "Project Structure" - "Modules"
151+
* Check `spring-javaformat-intellij-idea-plugin` icon turns to a plugin icon
152+
* "Plugin Deployment" - "Path to META-INF/plugin.xml"
153+
* Specify `<PROJECT>spring-javaformat/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/main/resources`
154+
155+
image::.github/images/setup-idea-plugin-module.png[Setup IntelliJ IDEA Plugin Module]
156+
157+
158+
159+
=== Setting up Gradle Plugin Development
160+
`spring-javaformat-gradle-plugin` module is a gradle plugin and requires gradle related classes.
161+
162+
To add gradle classes, convert this module to a gradle project.
163+
164+
* On the project pain, right-click `build.gradle` in `spring-javaformat-gradle-plugin` module
165+
* Select "Import Gradle Project"
166+
167+
168+
63169
=== Importing Into Other IDEs
64170
Maven is well supported by most Java IDEs. Refer to your vendor documentation.
65171

README.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ You can download the latest version from https://repo.spring.io/release/io/sprin
221221

222222

223223

224+
==== Enable the Plugin
225+
The plugin is automatically enabled when one or more of the following conditions match:
226+
227+
* `.springformat` file exists
228+
* For maven based project, `spring-javaformat-maven-plugin` plugin is defined in `pom.xml`
229+
* For gradle based project, `io.spring.javaformat` plugin is applied
230+
231+
232+
224233
=== About the Conventions
225234
Most of the coding conventions and style comes from the Spring Framework and Spring Boot projects.
226235
Spring Framework manually formats code, where as Spring Boot uses automatic formatting.

0 commit comments

Comments
 (0)