java - Maven - Dependency on module for Checkstyle not working -
project link: https://github.com/randomquestion/multimodulemavencheckstylesample
i have simple maven project multiple modules. i'm following this maven guide enable checkstyle on it. created common module named build-tools
(as per guide) , added checkstyle configuration in root pom file. i'm running weird issue.
when create new maven project scratch, mvn clean install
seems work fine including checkstyle. rename checkstyle file , update pom.xml
new name, build starts failing error could not find resource <new checkstyle file name>
. after that, can never build again. problem seems dependency on build-tools
module in root pom not working.
├── build-tools │ ├── build-tools\ (1).iml │ ├── pom.xml │ ├── src │ └── main │ └── resources │ └── default-checkstyle.xml ├── pom.xml
root pom.xml:
<modules> <module>build-tools</module> </modules> <properties> <checkstyle.config.location>default-checkstyle.xml</checkstyle.config.location> </properties> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-checkstyle-plugin</artifactid> <version>2.17</version> <dependencies> <dependency> <groupid>com.mycompany.app</groupid> <artifactid>build-tools</artifactid> <version>1.0-snapshot</version> </dependency> </dependencies> <executions> <execution> <id>validate</id> <phase>validate</phase> <configuration> <configlocation>default-checkstyle.xml</configlocation> <encoding>utf-8</encoding> <consoleoutput>true</consoleoutput> <failonviolation>true</failonviolation> </configuration> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
build-tools pom.xml
<parent> <groupid>com.mycompany.app</groupid> <artifactid>my-app</artifactid> <version>1.0-snapshot</version> </parent> <groupid>com.mycompany.app</groupid> <artifactid>build-tools</artifactid> <version>1.0-snapshot</version> <name>build-tools</name>
error:
info] scanning projects... [info] ------------------------------------------------------------------------ [info] reactor build order: [info] [info] my-app [info] build-tools [info] [info] ------------------------------------------------------------------------ [info] building my-app 1.0-snapshot [info] ------------------------------------------------------------------------ [info] [info] --- maven-clean-plugin:2.5:clean (default-clean) @ my-app --- [info] deleting /users/../workspace/my-app/target [info] [info] --- maven-checkstyle-plugin:2.17:check (validate) @ my-app --- [info] ------------------------------------------------------------------------ [info] reactor summary: [info] [info] my-app ............................................. failure [ 1.170 s] [info] build-tools ........................................ skipped [info] ------------------------------------------------------------------------ [info] build failure [info] ------------------------------------------------------------------------ [info] total time: 1.291 s [info] finished at: 2017-09-13t22:25:26-07:00 [info] final memory: 12m/309m [info] ------------------------------------------------------------------------ [error] failed execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project my-app: failed during checkstyle execution: unable find configuration file @ location: default-checkstyle.xml: not find resource 'default-checkstyle.xml'. -> [help 1]
any suggestions on might going wrong? why mvn install
not building build-tools
module first?
you current setup not work! when cloned project , tried build, fail not have build-tool
artifact in local repository while building parent pom.
this structure should have:
-- build-tools | | | - pom.xml | - app | | | - src | - pom.xml | - pom.xml
here parent pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.mycompany.app</groupid> <artifactid>my-app-parent</artifactid> <packaging>pom</packaging> <version>1.0-snapshot</version> <name>my-app-parent</name> <url>http://maven.apache.org</url> <!-- ~ modules --> <modules> <module>build-tools</module> <module>my-app</module> </modules> <build> <!-- ~ plugin settings --> <pluginmanagement> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-checkstyle-plugin</artifactid> <version>2.17</version> <dependencies> <dependency> <groupid>com.mycompany.app</groupid> <artifactid>build-tools</artifactid> <version>1.0-snapshot</version> </dependency> </dependencies> <executions> <execution> <id>validate</id> <phase>validate</phase> <goals> <goal>check</goal> </goals> </execution> </executions> <configuration> <configlocation>my-app-checkstyle.xml</configlocation> </configuration> </plugin> </plugins> </pluginmanagement> </build> <reporting> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-checkstyle-plugin</artifactid> <version>2.17</version> <configuration> <configlocation>default-checkstyle.xml</configlocation> </configuration> </plugin> </plugins> </reporting> </project>
build-tools/pom.xml as
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.mycompany.app</groupid> <artifactid>my-app-parent</artifactid> <version>1.0-snapshot</version> </parent> <artifactid>build-tools</artifactid> </project>
your other projects/pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.mycompany.app</groupid> <artifactid>my-app-parent</artifactid> <version>1.0-snapshot</version> </parent> <artifactid>my-app</artifactid> <packaging>jar</packaging> <name>my-app</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-checkstyle-plugin</artifactid> </plugin> </plugins> </build> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
rename checkstyle file name build-tools/src/main/resources/my-app-checkstyle.xml
Comments
Post a Comment