Note that I stumbled upon trying to add the war project to the dependency.
pom.xml
...
<groupId>hoge</groupId>
<artifactId>war-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
...
pom.xml
...
<dependencies>
<dependency>
<groupId>hoge</groupId>
<artifactId>war-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
...
When I try to maven build
Could not resolve dependencies for project ...
What are you saying. If you look closely
Could not transfer artifact hoge:war-sample:jar:1.0-SNAPSHOT ...
It seems that I went to look for the jar and could not find it, resulting in an error.
By default it will look for the jar, so if you want to put a war it seems you need to specify it.
pom.xml
...
<dependencies>
<dependency>
<groupId>hoge</groupId>
<artifactId>war-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
<type>war</type> <!--Explicit type-->
</dependency>
</dependencies>
...
I wondered if this would work, but this time there were many compilation errors. It seems that the classpath does not pass in the war file.
This page, And I was able to solve it by using mave-war-plugin.
pom.xml
...
<groupId>hoge</groupId>
<artifactId>war-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<attachClasses>true</attachClasses>
<classesClassifier>classes</classesClassifier>
</configuration>
</plugin>
</plugins>
</build>
...
If you insert maven-war-plugin and set attachClasses = true, The jar file is built at the same time as the war file.
After that, if you specify the classifier on the user side, it will go to see the jar, so the classpath will pass.
pom.xml
...
<dependencies>
<dependency>
<groupId>hoge</groupId>
<artifactId>war-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>classes</classifier>
<scope>test</scope>
</dependency>
</dependencies>
...
Confirm that maven build passes.
(It's a story that you should divide it into jars from the beginning ...)
Recommended Posts