I have maven structure
Parent - Server - ModuleA
Parent - Utils
Parent pom.xml
...
<groupId>by.services</groupId>
<artifactId>by.services</artifactId>
<name>Services</name>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<repositories>
<repository>
<id>OpenNMS Repository</id>
<name>OpenNMS Repository</name>
<url>http://repo.opennms.org/maven2/</url>
</repository>
<repository>
<id>Redhat GA Repository</id>
<name>Redhat GA Repository</name>
<url>https://maven.repository.redhat.com/ga/</url>
</repository>
</repositories>
<modules>
<module>utils</module>
<module>server</module>
<module>client</module>
</modules>
...
Server pom.xml
...
<parent>
<groupId>by.services</groupId>
<artifactId>by.services</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>by.mobile</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Server</name>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>by.services</groupId>
<artifactId>utils</artifactId>
<version>${utils.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
...
ModuleA pom.xml
...
<parent>
<groupId>by.services</groupId>
<artifactId>by.mobile</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ModuleA</artifactId>
<version>1.1</version>
<packaging>jar</packaging>
...
Utils pom.xml
<?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>by.services</groupId>
<artifactId>by.services</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>utils</artifactId>
<name>Utils</name>
<version>1.0.2</version>
<dependencies>
...
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>
${basedir}/../by.mobile/by.mobile.client/src/main/java
</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>
${basedir}/../by.mobile/by.news/src/main/java
</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>
${basedir}/../by.mobile/by.poxy/src/main/java
</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>${weblogic-maven-plugin.version}</version>
<configuration>
<isLibrary>true</isLibrary>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkMode>never</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Dependencies>
org.apache.cxf optional, org.apache.cxf.impl optional
</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I delete local repository and try compile project I have error
Failed to execute goal on project ModuleA: Could not resolve dependencies for project by.services:ModuleA:jar:1.0-SNAPSHOT: Failed to collect dependencies at by.services:utils:jar:1.0.2: Failed to read artifact descriptor for by.services:utils:jar:1.0.2: Failure to find by.services:by.services:pom:1.0-SNAPSHOT in http://repo.opennms.org/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of OpenNMS Repository has elapsed or updates are forced -> [Help 1]
My ModuleA don't see any class in Uitl model. Why?
Related
I have a problem when building specific module of my Maven projects
Project structure is like this :
data-importer (parent A)
|____ spring-batch (child B, jar)
|____ docker (child C)
I'm using IntelliJ (but tried with CLI and same behaviour) to build, when I'm building from the parent pom there is no problem but when I'm trying to build firstly spring-batch then docker I have the current error :
Could not find artifact ***.****.****.****:data-importer:pom:develop in nexus (http://**********/repository/maven-dev-group/)
I don't know why it's trying to get parent's pom, even if I have defined relativePath in child's POMs
I have the following POM (without the confidential parts) :
data-importer (parent A)
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>*******</groupId>
<artifactId>data-importer</artifactId>
<version>develop</version>
<packaging>pom</packaging>
<name>data-importer</name>
<description>data importer application for *</description>
<parent>
<groupId>*****.*****.******</groupId>
<artifactId>super-pom</artifactId>
<version>2.2.1-SNAPSHOT</version>
<relativePath/>
</parent>
<properties>
some versions
</properties>
<modules>
<module>spring-batch</module>
<module>docker</module>
</modules>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>*.*.*.*</groupId>
<artifactId>data-importer-spring-batch</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
**spring-batch (child A) **
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>****.****.**.***</groupId>
<artifactId>data-importer</artifactId>
<version>develop</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>data-importer-spring-batch</artifactId>
<version>develop</version>
<packaging>jar</packaging>
<name>spring-batch</name>
<description>data importer application for *</description>
<dependencies>
some dependencies
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<id>data-importer</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
one dependency
</dependencies>
</dependencyManagement>
</project>
docker (child C)
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>*.*.*.*</groupId>
<artifactId>data-importer</artifactId>
<version>develop</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>scpas-import</artifactId>
<version>develop</version>
<packaging>pom</packaging>
<name>docker</name>
<description>data importer application for docker</description>
<profiles>
<!-- Profil commun pour générer les images docker -->
<profile>
<id>docker</id>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!--Copy du jar spring batch dans target/docker/volumes/transferdata/import/data-importer -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-data-importer-jar-files</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includeGroupIds>*.*.*.*</includeGroupIds>
<includeArtifactIds>data-importer-spring-batch</includeArtifactIds>
<type>jar</type>
<outputDirectory>
${project.build.directory}/docker/volumes/transferdata/import/data-importer/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/docker</outputDirectory>
<resources>
<resource>
<directory>${basedir}/database</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>${basedir}/data-importer</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>${basedir}</directory>
<filtering>true</filtering>
<includes>
<include>Dockerfile</include>
</includes>
</resource>
<resource>
<directory>${basedir}</directory>
<filtering>true</filtering>
<includes>
<include>docker-compose.data-importer.yml</include>
</includes>
</resource>
<resource>
<directory>${basedir}</directory>
<filtering>true</filtering>
<includes>
<include>docker-entry-point.sh</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!--Génération de image docker-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>build-image</id>
<goals>
<goal>build</goal>
</goals>
<configuration>
<dockerDirectory>${project.build.directory}/docker</dockerDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
docker-push
</id>
some steps to push image in our registry
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>*.*.*.*</groupId>
<artifactId>data-importer-spring-batch</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Any idea why it's trying to get parent POM from registry ? (I don't want to push it as a mvn dependency)
Thx
I tried some tricks in settings.xml to never pull snapshots and releases from registry but nothing works except building full project from parent's POM
Since access to the parent-POM is given, you can just locally install it beforehand.
This will solve looking parent up a repository.
What you need is to call Maven with -N (non-recursively) option mvn install -N and then you should be able to use it.
So, I tried making another project depending on my base project, it worked and now for some reason my base project won't build correctly.
Whenever I build my maven project, no jar is outputted anywhere. I checked my build path, and the target folder.
My pom.xml:
<?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>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>1.1</version>
<repositories>
...
</repositories>
<dependencies>
...
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
...
</includes>
<excludes>
<exclude>target/</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>...</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now, with my original builds they still had the target folder for some reason, but now nothing is built at all.
I'm compiling my project with mvn clean package, and failed with package does not exist.
The detail command:
Get the jar file target/xxxx.jar by running mvn clean package in source project.
install this jar file by running mvn install:install-file -Dfile=lib/xxxx.jar -DgroupId=com.company -DartifactId=source-package-name -Dversion=1.0.0 -Dpackaging=jar
add code to target project, which will use some functions in source project
compile target project by running mvn clean package, and it just failed with package does not exist
here is the source project pom.xml
<?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>
<groupId>com.company</groupId>
<artifactId>source-package-name</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>source-package-name</name>
<description>xxxx</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx6144m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
here is the target project pom.xml
<?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>
<groupId>com.company</groupId>
<artifactId>target-package-name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>target-package-name</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.7</jdk.version>
<smartv-common.version>0.3.5s</smartv-common.version>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<!-- Exclude those since they are copied from the profile folder for
the build -->
<exclude>system.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<finalName>xxxxx</finalName>
<!-- Set a compiler level -->
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
http://stackoverflow.com/questions/12729513/how-to-overwrite-files-in-the-war-file-during-maven-build -->
<webResources>
<!-- Resources from the activated profile folder -->
<resource>
<targetPath>WEB-INF/classes/</targetPath>
<includes>
<include>system.properties</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
Ideally, you shouldn't use a Spring Boot application (something that's been repackaged) as a dependency. From the documentation:
Like a war file, a Spring Boot application is not intended to be used as a dependency. If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module. The separate module can then be depended upon by your application and other projects.
If the proposed solution isn't possible in your situation, the documentation goes on to describe an alternative:
If you cannot rearrange your code as recommended above, Spring Boot’s Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency. The executable archive cannot be used as a dependency as the executable jar format packages application classes in BOOT-INF/classes. This means that they cannot be found when the executable jar is used as a dependency.
To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as dependency.
To configure a classifier of exec in Maven, the following configuration can be used:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
I have he following structure of a maven web application
When I execute mvn install command it's creating war file but if you will look in target directory/sureportal you can easily see that lots of sub folders inside webapps directory are missing. What is wrong?
pom.xml file
<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.nokia</groupId>
<artifactId>sureportal</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<name>sureportal Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>sureportal</finalName>
</build>
</project>
You can have a maven-war-plugin and configure to include empty folders.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<includeEmptyDirectories>true</includeEmptyDirectories>
</configuration>
</plugin>
In addition to the answer of sbaitmangalkar, insert the maven-war-plugin to the build section of your POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<!- if you don't have a web.xml, otherwise "true" -->
<failOnMissingWebXml>false</failOnMissingWebXml>
<includeEmptyDirectories>true</includeEmptyDirectories>
<includes>**/*</includes>
<!-- if want your web files to be filterd -->
<webResources>
<resource>
<directory>src/main/webapp</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/META-INF</directory>
<!-- only if needed in your project -->
<targetPath>/META-INF</targetPath>
<includes>
<include>context.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
This tells the build process explicitly what to do.
Try running mvn clean install. This will clear your compiled files first and ensures that all of it is compiled from scratch. Please check this thread for more details how-is-mvn-clean-install-different-from-mvn-install
Good luck.
I have created a maven application with JSF, Spring and JSF facets. The goals clean (deleting the target directory) and compile are working fine. But when I am running Maven with package option, I see that in the generated xxx-SNAPSHOT.war file the webapp and WEB-INF directory are copied recursively.
The Maven version is 3.1.0.
Please see the below 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.organization.elr</groupId>
<artifactId>employeerepository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Employee Location Repository</name>
<properties>
<version.spring>3.1.2.RELEASE</version.spring>
<version.aopalliance>1.0</version.aopalliance>
<version.standard.taglibs>1.1.2</version.standard.taglibs>
<version.commons.logging>1.1.1</version.commons.logging>
</properties>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<outputDirectory>${basedir}/src/main/WEB-INF/classes</outputDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<testOutputDirectory>${basedir}/src/main/WEB-INF/classes/test</testOutputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webappDirectory>${basedir}/src/main/webapp</webappDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Any ideas how I can avoid this?
Thanks in advance,
Mouli.
This makes no sense
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<outputDirectory>${basedir}/src/main/WEB-INF/classes</outputDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<testOutputDirectory>${basedir}/src/main/WEB-INF/classes/test</testOutputDirectory>
Remove those lines. You're building application to source dir.
This have no sense as well
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
Why do you have .java files in resources in the first place?