Maven profile dependency order - java

I have something like this:
<profiles>
<profile> <id>a</id>
<dependencies> <dependency> <x> </dependency> </dependencies>
</profile>
<profile> <id>b</id>
<dependencies> <dependency> <y> </dependency> </dependencies>
</profile>
</profiles>
<dependencies>
<z>
</dependencies>
So profile a has a dependency x, profile b has dependency y. BOTH have dependency z. The issue is, maven puts dependency z before x or y. I need it the other way around. I need x/y to be override z.
How can I do this? My current workaround is to put the dependency of z in both the profiles like so:
<profiles>
<profile> <id>a</id>
<dependencies>
<dependency> <x> </dependency>
<dependency> <z> </dependency>
</dependencies>
</profile>
<profile> <id>b</id>
<dependencies>
<dependency> <y> </dependency>
<dependency> <z> </dependency>
</dependencies>
</profile>
</profiles>
This works but seems like there should be a better way to do it.

Related

Simple Camel application doesn't work with the Quartz component

I'm trying to run a simple Camel route using Quartz component to schedule a job. In this example is like an hello word every minute.
This is the example route:
public void configure() throws Exception {
from("quartz://myname?cron=0+ *+ *+ ?+ *+ *")
.to("log:hello");
}
When I run the application I get the following error:
An attempt was made to call a method that does not exist. The attempt was made from
the following location:
org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:150)
The following method did not exist:
'org.quartz.Trigger org.quartz.Scheduler.getTrigger(java.lang.String, java.lang.String)'
The method's class, org.quartz.Scheduler, is available from the following locations:
jar:file:/C:/Users/andre/.m2/repository/org/quartz-scheduler/quartz/2.3.2/quartz-2.3.2.jar!/org/quartz/Scheduler.class
The class hierarchy was loaded from the following locations:
org.quartz.Scheduler: file:/C:/Users/andre/.m2/repository/org/quartz-scheduler/quartz/2.3.2/quartz-2.3.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible
version of org.quartz.Scheduler
But actually I don't get how I should correct the classpath of my application.
This is the pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mycompany</groupId>
<artifactId>camel-ose-springboot-xml</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Fabric8 :: Quickstarts :: Spring-Boot :: Camel XML</name>
<description>Spring Boot example running a Camel route defined in XML</description>
<properties>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<docker.image.version>1.9</docker.image.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<fuse.version>7.11.0.fuse-sb2-7_11_0-00028-redhat-00001</fuse.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.redhat-fuse</groupId>
<artifactId>fuse-springboot-bom</artifactId>
<version>7.11.0.fuse-sb2-7_11_0-00028-redhat-00001</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
<!-- use the same version as your Camel core version -->
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>red-hat-ga-repository</id>
<url>https://maven.repository.redhat.com/ga</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>red-hat-ga-repository</id>
<url>https://maven.repository.redhat.com/ga</url>
</pluginRepository>
</pluginRepositories>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.redhat-fuse</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${fuse.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>openshift</id>
<build>
<plugins>
<plugin>
<groupId>org.jboss.redhat-fuse</groupId>
<artifactId>openshift-maven-plugin</artifactId>
<version>${fuse.version}</version>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<enricher>
<excludes>
<exclude>fmp-openshift-route</exclude>
</excludes>
</enricher>
<resources>
<labels>
<pod>
<property>
<name>com.company</name>
<value>Red_Hat</value>
</property>
<property>
<name>rht.prod_name</name>
<value>Red_Hat_Integration</value>
</property>
<property>
<name>rht.prod_ver</name>
<value>7.9</value>
</property>
<property>
<name>rht.comp</name>
<value>spring-boot-camel-xml</value>
</property>
<property>
<name>rht.comp_ver</name>
<value>${fuse.bom.version}</value>
</property>
</pod>
</labels>
</resources>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jkube.generator.from>registry.redhat.io/fuse7/fuse-java-openshift-rhel8:${docker.image.version}</jkube.generator.from>
</properties>
</profile>
<profile>
<id>java11</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<properties>
<jkube.generator.from>registry.redhat.io/fuse7/fuse-java-openshift-jdk11-rhel8:${docker.image.version}</jkube.generator.from>
</properties>
</profile>
<profile>
<id>java17-build</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.5</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
There is a conflict in Quartz version somewhere, indeed the version of camel-quartz that you use (2.23.2.fuse-7_11_0-00037-redhat-00001), expects Quartz v1 while you end up with Quartz v2 which causes the issue.
You have two ways to fix your problem:
Keep on using Quartz v1
In that case, you will have to force the version of Quartz in your pom file by adding:
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
Switch to Quartz v2
In that case, you will have to change the camel-quartz artifact for camel-quartz2-starter as next:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2-starter</artifactId>
<!-- use the same version as your Camel core version -->
</dependency>
Then change the URI of the Quartz endpoint by specifying quartz2 instead of quartz as next:
public void configure() throws Exception {
from("quartz2://myname?cron=0+ *+ *+ ?+ *+ *")
.to("log:hello");
}
The choice is up to you, but I would definitely recommend switching to Quartz v2.

Problem with dependencyManagement and dependency versions

I have problem with relations of pom, with dependency versions etc. Below my structure:
My MAIN pom, which gives me the order to build of all projects
<groupId>com.xyz</groupId>
<artifactId>yxz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>xyz</name>
<modules>
<module>commons</module>
<module>projectA</module>
<module>ProjectB</module>
...
<module>ProjectX</module>
</modules>
COMMONS pom, it is designed to have common dependencies and properties, without any parent
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<name>commons</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.version>3.8.1</maven.compiler.version>
<java.version>11</java.version>
<lombok.version>1.18.24</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
ProjectA pom, include commons dependency, with spring-boot in parent,
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectA</name>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
<dependency>
some dependencies from org.springframework.cloud
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
</build>
ProjectB pom, include commons dependency, with custom framework in parent,
<parent>
<groupId>com.customframework</groupId>
<artifactId>custom.framework</artifactId>
<version>1.8.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>projectB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectB</name>
<properties>
<java.version>11</java.version>
<customeframework.feign.version>10.12</customeframework.feign.version>
</properties>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>11.8</version>
</dependency>
other feign dependecies with 11.8 version
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.customframework</groupId>
<artifactId>custom.framework.feign</artifactId>
<version>${customeframework.feign.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
</build>
When i build my all projects then:
projectA has lombok with version from springframework.cloud dependency management, not with version from commons
ProjectB has similar problem with feign, if i add feign dependency with version 11.8, maven use version from customframework (version 9.x)
What i want to do:
I tried add bom pom file, like next module to MAIN pom but how should i add it when i have other dependency management from springframework.cloud
i have 5-6 projects with spring boot parent, some with quarqus and with custom framework and i want configure all dependency versions and parent spring boot versions in one file
If you want to have the same dependencies in all modules then how about you define <dependencyManagement> with all required BOMs and versions in one place (e.g. in commons module)?
It won't bother the modules if they don't include some of the dependencies but it will make sure that all the modules have the same dependencyManagement rules.

Upgrading magnolia to 5.6.1, vaadin resources

After Tomcat starts Magnolia, I always get the following error:
17:04:36.781 [localhost-startStop-1] ERROR info.magnolia.module.ModuleManagerImpl - Can't start module ui-framework
com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: com/vaadin/data/util/converter/Converter$ConversionException
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2216) ~[guava-23.1-jre.jar:?]
And later when I request the admin page, I keep getting these errors.
INFO: Requested resource [/VAADIN/themes/valo/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
Jan 23, 2018 12:50:50 PM com.vaadin.server.VaadinServlet serveStaticResourcesInVAADIN
INFO: Requested resource [/VAADIN/themes/valo/favicon.ico] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
Amongst other things, I've included everything I think I need in the dependencies for the UI framework:
<project>
<!-- ... -->
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-framework</artifactId>
<version>${magnoliaUiVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-admincentral</artifactId>
<version>${magnoliaUiVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-contentapp</artifactId>
<version>${magnoliaUiVersion}</version>
</dependency>
</project>
Edit 1:
So I've found that magnolia-resources is version 2.4 in the Magnolia Travel Demo. When you run it with this version (and Magnolia 5.6.1 Core) the login screen doesn't display the Magnolia logo. When I upgraded to version 2.6, the Magnolia logo appeared.
Edit 2:
I'm now able to login, and the admincentral is stuck on loading. After a few seconds, the following message pops up:
Failed to load the widgetset: ./../VAADIN/widgetsets/info.magnolia.widgetset.MagnoliaWidgetSet/info.magnolia.widgetset.MagnoliaWidgetSet.nocache.js?1516882029507
POM below:
<?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/maven-v4_0_0.xsd ">
<modelVersion>4.0.0</modelVersion>
<groupId><!-- hidden --></groupId>
<artifactId><!-- hidden --></artifactId>
<name><!-- hidden --></name>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<description><!-- hidden --></description>
<properties>
<magnoliaVersion>5.6.1</magnoliaVersion>
<magnoliaUiVersion>5.6.1</magnoliaUiVersion>
<magnoliaDamVersion>2.3</magnoliaDamVersion>
<magnoliaPasswordManagerVersion>1.2</magnoliaPasswordManagerVersion>
<magnoliaImagingVersion>3.4</magnoliaImagingVersion>
<magnoliaCategorizationVersion>2.6</magnoliaCategorizationVersion>
<magnoliaTemplatingVersion>1.2</magnoliaTemplatingVersion>
<magnoliaResourcesVersion>2.6</magnoliaResourcesVersion>
<magnoliaFormVersion>2.4</magnoliaFormVersion>
<magnoliaSiteVersion>1.2</magnoliaSiteVersion>
<vaadinVersion>8.1.5</vaadinVersion>
<mavenCompilerVersion>3.6.1</mavenCompilerVersion>
<tomcat7Version>2.2</tomcat7Version>
</properties>
<dependencyManagement>
<dependencies>
<!-- info.magnolia -->
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-project</artifactId>
<version>${magnoliaVersion}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-project</artifactId>
<version>${magnoliaUiVersion}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.magnolia.cache</groupId>
<artifactId>magnolia-cache-core</artifactId>
<version>${magnoliaVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.site</groupId>
<artifactId>magnolia-site</artifactId>
<version>${magnoliaSiteVersion}</version>
</dependency>
<!-- info.magnolia.dam -->
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-templating</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-jcr</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-api</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-app</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-imaging</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<!-- info.magnolia.imaging -->
<dependency>
<groupId>info.magnolia.imaging</groupId>
<artifactId>magnolia-imaging</artifactId>
<version>${magnoliaImagingVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.imaging</groupId>
<artifactId>magnolia-imaging-support</artifactId>
<version>${magnoliaImagingVersion}</version>
</dependency>
<!-- info.magnolia.passwordmanager -->
<dependency>
<groupId>info.magnolia.passwordmanager</groupId>
<artifactId>magnolia-module-password-manager</artifactId>
<version>${magnoliaPasswordManagerVersion}</version>
</dependency>
<!-- info.magnolia.resources -->
<dependency>
<groupId>info.magnolia.boms</groupId>
<artifactId>magnolia-external-dependencies</artifactId>
<version>${magnoliaVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>info.magnolia.resources</groupId>
<artifactId>magnolia-resources</artifactId>
<version>${magnoliaResourcesVersion}</version>
</dependency>
<!-- info.magnolia.categorization -->
<dependency>
<groupId>info.magnolia.categorization</groupId>
<artifactId>magnolia-categorization</artifactId>
<version>${magnoliaCategorizationVersion}</version>
</dependency>
<!-- info.magnolia.templating -->
<dependency>
<groupId>info.magnolia.templating</groupId>
<artifactId>magnolia-templating-kit</artifactId>
<version>${magnoliaTemplatingVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.templating</groupId>
<artifactId>magnolia-templating-essentials-models</artifactId>
<version>${magnoliaTemplatingVersion}</version>
</dependency>
<!-- info.magnolia.form -->
<dependency>
<groupId>info.magnolia.form</groupId>
<artifactId>magnolia-form</artifactId>
<version>${magnoliaFormVersion}</version>
</dependency>
<!-- com.vaadin -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-compatibility-server</artifactId>
<version>${vaadinVersion}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<version>${vaadinVersion}</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>magnolia.public</id>
<url>https://nexus.magnolia-cms.com/content/groups/public</url>
<snapshots />
</repository>
<!-- IF YOU NEED MODULES FROM THE ENTERPRISE VERSION, UNCOMMENT THE FOLLOWING REPOSITORY -->
<!--
<repository>
<id>magnolia.enterprise.releases</id>
<url>https://nexus.magnolia-cms.com/content/repositories/magnolia.enterprise.releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
-->
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profileName>default</profileName>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7Version}</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${mavenCompilerVersion}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module><!-- hidden -->-webapp</module>
<module><!-- hidden -->-blossom</module>
</modules>
</project>
Any thoughts?
Please have a look at https://documentation.magnolia-cms.com/display/DOCS56/Upgrading+to+Magnolia+5.6.x. Especially part of Vaadin8 Upgrade and BOM. I believe you have to import dependency management section from BOM project.
Hope this helps,
Cheers,

Spring Boot: different dependencies for IDE and package

What is the best approach to handle different dependencies trees for Spring Boot running under Eclipse (Spring Tools Suite)?
I'd like to run from IDE with Logback library enabled. And packaged version (uberJar) should not contain Logback because I'm using Log4j2 there. Build is managed by Maven.
Thank you, guys! I've combined your advice and config from Spring docs.
Finally I got:
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>runtime</id>
</profile>
<profile>
<id>build</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

Maven profile not seeing dependency in child module

I have searched over SO and Internet, but no success. This is what I have in short:
Multimodule project with dev and appserv profile. When dev profile is used (just mvn clean install because default=true), then load specific dependencies. One dependency is Child-A that must be loaded in Child-B. I am building always from parent POM.
I have profile defined in parent POM with activation and in Child-B I have same profile with dependencies.
This is my parent POM:
<project ..>
<groupId>com.organisation</groupId>
<artifactId>project-name</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>child-b</module>
<module>child-a</module>
</modules>
<properties>
<javax.ws.rs.version>2.0</javax.ws.rs.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- project dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>child-a</artifactId>
<version>${project.version}</version>
</dependency>
<!-- build dependencies -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>child-a</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<profile>
<id>app-server</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>app-server</value>
</property>
</activation>
</profile>
</profiles>
</project>
My Child-B module that calls Child-A, the IDE as well when building Child-B doesn't see Child-A's classes.
<project ..>
<parent>
<groupId>com.organisation</groupId>
<artifactId>project-name</artifactId>
<version>1.0</version>
</parent>
<artifactId>child-b</artifactId>
<packaging>jar</packaging>
<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-a</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>app-server</id>
<dependencies>
...
</dependencies>
</profile>
</profiles>
<dependencies>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
</project>
I don't see what is wrong here and can't understand where the problem is, why Child-B doesn't take Child-A as dependency. In parent POM inside profile I have tried to remove the dependencyManagement, but the result was still same - Child-A not seen in Child-B module. Apparently without the profiles everything was working fine.
In Child-b you put a dependency to child-b instead of a dependency to child-a
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-b</artifactId>
</dependency>
instead of
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-a</artifactId>
</dependency>

Categories