I was in trouble because I didn't think that there was a plug-in if it was as famous as ESLint, so I solved it. I don't want to install node by myself due to version issues, so if I'm using Maven in a Java project, I thought about how to install a plugin, so it looks like this article.
Adopt Open JDK Hotspot 11.0.3 Maven 3.6.0
I will omit it here. Any Maven project is fine.
I will do npm install
in Maven, so I will make it first.
package.json
{
"dependencies": {},
"devDependencies": {
"eslint": "^6.5.1"
}
}
For the time being, it looks like this at the minimum. Since there are many releases, please read the version as appropriate.
Since it can be installed with a plugin called frontend-maven-plugin
, we will set it first.
Basically, you can set it as officially.
pom.xml
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<configuration>
<nodeVersion>v10.16.3</nodeVersion>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
</plugin>
./mvnw generate-resources
will create node related files.
If you don't have the file to run ESlint, you need to initialize it here.
However, just note that the node executable is in the node
folder of the project root, so you have to add it to your PATH.
export PATH=node/:$PATH
All you have to do is run it and set it up. I was thinking of setting it from Gitbash on Windows first, but it didn't work, so I recommend doing it on a Mac.
node_modules/.bin/eslint --init
Since I want to set the same rule on the Eclipse side in the story of the project under development in Eclipse, I have separated the inited hidden file with a symbolic link. It seems that you can only use Tern to do it in Eclipse, but it is a little convenient because you can follow the same rules.
I feel sad to develop Javascript using Eclipse, so I personally want to use VS Code only when playing with Javascript, but this time I can do all development on Eclipse for the convenience of the project. We are implementing this kind of response because we have to do so.
Now that we are ready, we will play with pom.xml again so that ESLint can be executed from Maven.
This is done using ʻexec-maven-plugin. I wish I could do it with
frontend-maven-plugin`, but it didn't work so I'm trying to use another plugin.
Here, it is set to call eslint_exec.sh from the bash command.
pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>verify</phase>
<id>exec-eslint</id>
<configuration>
<executable>bash</executable>
<arguments>
<argument>eslint_exec.sh</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
The contents of eslint_exec.sh look like this. Setting under node in PATH is troublesome to have it set in various environments, so I decided to execute it in this. The rest is just running ESLint. ʻExit 0` is included because I didn't want to make an error even if I got caught in the check when running with Jenkins.
eslint_exec.sh
export PATH=node/:$PATH
node_modules/.bin/eslint src/main/resources/static/js/*/**
exit 0
Since verify will do what you want to do this time, set the goal setting to verify.
./mvnw verify
I don't think it's possible to develop Javascript in this age, so I thought it would have been better to think of a way to build it a little easier overall.
Recommended Posts