I have these two modules WEB and Database. I have set Database as a dependency for WEB. When I open the code in WEB, the imported Database is no longer in red. However, when I execute commands: clean, install, cargo:run, the code fails saying the imported code does not exist.
Edit
pom.xml in WEB module. It is still not working.
<?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">
<parent>
<artifactId>LNU-Project</artifactId>
<groupId>com.project</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>WEB</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>Database</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
Related
I am using a multi-module approach in Spring boot application. My directory structure is like
package name
|_bom
|__common-test
|__service
|_src/test/java/TestFile.java
I have put test related dependencies in pom.xml of common-test and accessing them in test folder of service. I am able to access most of the dependencies in TestFile.java but not the dependency mentioned below. This is the last dependency in pom.xml of common-test. Following the same structure I am able to use mockito dependency but not this one.
I have defined related properties in bom/pom.xml which are to be used in common-test/pom.xml. Using this approach for first time and not sure how to achieve this. Basically, I need to maintain test related dependencies in common-test pom.xml and not include it in service.
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
pom.xml of common-test have this dependency
<?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">
<parent>
<artifactId>projeectname</artifactId>
<groupId>in.packagename.mint</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>projeectname-common-test</artifactId>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>in.packagename.mint</groupId>
<artifactId>projeectname-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- project dependencies -->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
</dependency>
</dependencies>
</project>
pom.xml of bom
<?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 coordinates -->
<parent>
<groupId>in.packagename.mint</groupId>
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>projectname-bom</artifactId>
<properties>
<junit.jupiter.migration-support.version>5.7.0</junit.jupiter.migration-support.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.5.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit.jupiter.migration-support.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
I have tried deleting .m2 folder and building all these bom, common-test, etc. separately and runnning mvn install but this dependency issue is not resolved and not able to import it in service test folders.
I'm trying to create a multi module Maven Spring project:
Parent
|-Bom
|-Customers
|- Customers-main
|- Customers-client
|- other modules...
The idea is all projects import the bom so I can keep version consistent across modules.
When trying to build the Customers module, I get these errors:
[ERROR] The project com.imgarena:customers:0.0.1-SNAPSHOT (C:\dev\IMGArena\customers\pom.xml) has 2 errors
[ERROR] 'dependencies.dependency.version' for io.springfox:springfox-swagger2:jar is missing. # line 52, column 21
[ERROR] 'dependencies.dependency.version' for io.springfox:springfox-swagger-ui:jar is missing. # line 56, column 21
Inside IntelliJ, the versions are resolved correctly (it even shows the gutter icon that jumps to the bom when clicked):
But when running with Maven 3.6.3 CLI, I got the error.
Parent pom.xml: (most dependencies are removed for brevity)
<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.imgarena</groupId>
<artifactId>parent</artifactId>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/>
</parent>
<!-- chaged fom jar to pom -->
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>customers</module>
</modules>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<spring-cloud.version>2020.0.0</spring-cloud.version>
<springfox-version>3.0.0</springfox-version>
</properties>
</project>
Bom 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.imgarena</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>com.imgarena</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
customers 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">
<parent>
<artifactId>parent</artifactId>
<groupId>com.imgarena</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>customers</artifactId>
<packaging>pom</packaging>
<modules>
<module>customers-client</module>
<module>customers-main</module>
</modules>
<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>
<dependency>
<groupId>com.imgarena</groupId>
<artifactId>bom</artifactId>
<type>pom</type>
<scope>import</scope>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</project>
Apparently the reason was I was missing including the bom as a module in the parent pom:
<modules>
<module>customers</module>
<module>bom</module>
</modules>
Don't know exactly why, but once I added this everything worked.
I have a custom controller service that I want to use together with the ConnectWebSocket processor. The controller service depends on nifi-websocket-services-api and does not need a custom api (the my-customer-controller-service-api folder is empty). I have written a test for the controller service and it is passing.
However I cannot select the controller service, because ConnectWebSocket only accepts a controller service api from nifi-websocket-service-api-nar.
I want to avoid to recode the entire ConnectWebSocket processor. So my question is:
Is it possible to configure the dependencies such that my custom controller service uses the api that comes from nifi-websocket-service-api-nar?
pom.xml of controller-service:
<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.mydomain</groupId>
<artifactId>nifi-controllerservice-bundle</artifactId>
<version>1.9.2</version>
</parent>
<artifactId>nifi-controllerservice</artifactId>
<packaging>jar</packaging>
<dependencies>
<!-- normal dependencies -->
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-processor-utils</artifactId>
<version>1.9.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-websocket-services-api</artifactId>
<version>1.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-websocket-services-jetty</artifactId>
<version>1.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-ssl-context-service-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
</dependencies>
pom.xml of controller-service-nar
<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.mydomain</groupId>
<artifactId>nifi-controllerservice-bundle</artifactId>
<version>1.9.2</version>
</parent>
<artifactId>nifi-controllerservice-nar</artifactId>
<version>1.9.2</version>
<packaging>nar</packaging>
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<source.skip>true</source.skip>
</properties>
<dependencies>
<dependency>
<groupId>com.mydomain</groupId>
<artifactId>nifi-controllerservice</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-websocket-services-jetty</artifactId>
<version>1.9.2</version>
<scope>nar</scope>
</dependency>
</dependencies>
</project>
root 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>
<parent>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-nar-bundles</artifactId>
<version>1.9.2</version>
</parent>
<groupId>com.mydomain</groupId>
<artifactId>nifi-controllerservice-bundle</artifactId>
<version>1.9.2</version>
<packaging>pom</packaging>
<modules>
<module>nifi-comtom</module>
<module>nifi-comtom-nar</module>
</modules>
</project>
This should be the standard way processors and controller services work...
Processors depend on an interface which comes from the service API NAR, and controller service implementations implement that interface. The framework then knows all the implementations of that interface which allows is to provide the possible services that can be used.
Without seeing your project and poms it is hard to say what the problem is, but most likely it is a dependency issue. Your project structure should have two Maven modules, one that produces a jar for your service impl, lets call this one custom-service, and then one that packages the NAR, lets call this custom-service-nar.
The custom-service module should have a provided dependency on nifi-websocket-services-api, this allows it to compile, but we don't want to bundle that API since at runtime it will come from another NAR.
The custom-service-nar module should have a dependency of type NAR on the nifi-websocket-services-api-nar.
https://cwiki.apache.org/confluence/display/NIFI/Maven+Projects+for+Extensions#MavenProjectsforExtensions-LinkingProcessorsandControllerServices
Trying to understand why my effective pom is missing inherited dependencies.
I have a very simple set up, in fact, identical to the one shown in "Creating a Multi Module Project" guide on Spring.io.
The root 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>org.springframework</groupId>
<artifactId>gs-multi-module</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<modules>
<module>library</module>
<module>application</module>
</modules>
</project>
The library module pom.xml is this (notice my addition of com.google.http-client dependency:
<?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.example</groupId>
<artifactId>gs-multi-module-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The module that lists the "library" module as a dependency is this:
<?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.example</groupId>
<artifactId>gs-multi-module-application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>gs-multi-module-library</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
YET, the effective pom.xml does NOT show com.google.http-client as one of the dependencies for this last "application" module:
cd application
mvn help:effective-pom
Why is this happening and how do I make sure that regular maven dependency transitivity still works?
I tried the sample provided and I am seeing dependencies resolved as expected:
Effective POM(includes library reference):
Resolved dependencies(includes google-httpclient):
Here is the answer:
help:effective-pom does NOT show transitive dependencies.
To show all the dependencies that are brought in as a result of transitive dependencies, use:
mvn dependency:tree
Let's say I have a multi-module maven project. One of the project's POM file is the following:
<?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>some.group</groupId>
<artifactId>parent-artifact</artifactId>
<version>0.14.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>artifact-x</artifactId>
<packaging>jar</packaging>
<name>Artifact X</name>
<dependencies>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-a</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-b</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-c</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-d</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-e</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Let's say for some reason, I want to move some of the dependencies in this POM file to a profile. So, I move artifact-c, artifact-d, artifact-e to only be dependencies when using profile-1. profile-1 is also used in other POMs in the project. My new POM now becomes:
<?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>some.group</groupId>
<artifactId>parent-artifact</artifactId>
<version>0.14.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>artifact-x</artifactId>
<packaging>jar</packaging>
<name>Artifact X</name>
<dependencies>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-a</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-b</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>profile-1</id>
<dependencies>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-c</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-d</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>artifact-e</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
When building, I run mvn -Pprofile-1 clean package at the top-level POM in both cases. My expectation was that moving dependencies to a profile shouldn't change anything when -Pprofile-1 was specified. But that didn't happen - some of the plugins started behaving erroneously - for ex. the maven-shade-plugin didn't put artifact-c, artifact-d and artifact-e in the shaded jar etc.
Am I doing something wrong? Are profiles not supposed to work like this?
Are these two POM files not equivalent even when used with -Pprofile-1?
Even though the pom.xml allows you to define it like this, you shouldn't (call it a design flaw). Most of the times it doesn't make sense to just add dependencies in a profile. Valid constructions are dependencies based on OS or on JDK version.
Also remember that the pom.xml also acts as "consumer-pom", so other projects using this artifact will read this pom file to get the transitive dependencies. In such case you can't active a profile anymore.
In conclusion: don't try to solve this with profiles. There must be a better solution.