Why I get cannot be resolved with maven project - java

I am building a Dropwizard project.
(start with:https://dropwizard.github.io/dropwizard/getting-started.html)
I create a project in eclipse, but don't understand why I get "cannot be resolved".
This is errors:
This is 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>foo.bar.app</groupId>
<artifactId>mvn-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mvn-test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dropwizard.version>INSERT VERSION HERE</dropwizard.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
</dependency>
</dependencies>
</project>
Any one can help?
I don't know how to import the package, i really have no idea with maven dependency.
Thanks.

You have to define ${dropwizard.version} tag between in pom.xml like this :
<properties>
<dropwizard.version>0.7.0</dropwizard.version>
</properties>

You have to insert your specific dropwizard.version:
<dropwizard.version>**INSERT VERSION HERE**</dropwizard.version>
so it can be used in your pom:
<version>${dropwizard.version}</version>

Related

Maven multi module prroject circular dependency issue which i am unable to solve

I have tried the most common fixes suggested on stackkoverflow but i am still unable to solve my problem. Exclusions/dependency helpers/plugins etc.
I have a parent module and 2 sub modules which i'd like to commuunicate with eachother. module one downloads data and module 2 does some pre processing before it is stored in a databbase.
To realize this i added the dependencies to the modules itself in the parrents pom.xml this causes the problem of course but i'd figuure i could just add them and force it to ignore duplicate dependencies or something.
How else can i make the 2 modules talk communicate to eachother?
any advice or help would be really appreciated!
<?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.algoframework</groupId>
<artifactId>AlgoFramework</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>binance-api-custom</module>
<module>influxdb-controller</module>
</modules>
<dependencies>
<dependency>
<groupId>com.algoframework</groupId>
<artifactId>binance-api-custom</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.algoframework</groupId>
<artifactId>influxdb-controller</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
</project>
-----------------------------------------------
<?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>AlgoFramework</artifactId>
<groupId>com.algoframework</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>binance-api-custom</artifactId>
<dependencies>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.asynchttpclient</groupId>
<artifactId>async-http-client</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>org.asynchttpclient</groupId>
<artifactId>async-http-client-extras-retrofit2</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
</project>
-----------------------------------------------
<?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>AlgoFramework</artifactId>
<groupId>com.algoframework</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>influxdb-controller</artifactId>
<dependencies>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>6.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>flux-dsl</artifactId>
<version>6.1.0</version>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
</project>
You cannot have two modules calling each other.
Either you merge them, or you change your design in a way that calls only go one-way, i.e. only module A calls module B but not vice versa.

maven dependency version issues

I just got in issue related to Maven and Dependent JAR version. I create following project to analyze issue.
I created App_1.jar which is using spring version 4.2.9.
I created App_2.jar which is using spring version 4.3.4.
I created App_3.jar which is using spring version 4.3.6.
I created App_Main.war which will App_1.jar, App_2.jar, App_3.jar.
According to maven if you use different version it will use the latest one but in my case it using the spring version of jar which i included first which is App_1.jar and its version is 4.2.9.
Here is the code.
**App_1 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.ksh</groupId>
<artifactId>App_1</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>App_1</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.9.RELEASE</version>
</dependency>
</dependencies>
</project>
**App_2 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.ksh</groupId>
<artifactId>App_2</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>App_2</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
</dependencies>
</project>
**App_3 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.ksh</groupId>
<artifactId>App_3</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>App_3</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
</dependencies>
</project>
App_Main 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>App_Main</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>App_Main Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.ksh</groupId>
<artifactId>App_1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.ksh</groupId>
<artifactId>App_2</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.ksh</groupId>
<artifactId>App_3</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<finalName>App_Main</finalName>
</build>
</project>
Where did you read maven use the latest one?
For transitives dependencies Maven uses a "nearest-wins" strategy to resolves version conflicts, and that means it will use the version of the closest dependency to your project in the tree of dependencies.
Maven transitive dependencies
One possible solution is use the <dependencyManagement> to resolve your conflicts.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>spring_context_version_you_want_to_use</version>
</dependency>
</dependencies>
</dependencyManagement>
Maven dependency managament
You can check your tree of dependencies with the command:
mvn dependency:tree -Dverbose -Dincludes=your-jar
Resolving conflicts using the dependency tree

Why the maven child referencing versions from BOM does not work?

I created this example POM file so that I do not need the dependency versions replicated in each child project. My requirement is that the thirdparty version need not be provided for each project. Each project should inherit the library versions from the bom file. I created the example based on the documentation of Maven dependencies. My maven version is Apache Maven 3.2.5
I am getting the error below
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.test.testapp:test-app:1.0-SNAPSHOT (/Users/skoya/workspace/test-app/pom.xml) has 2 errors
[ERROR] 'dependencies.dependency.version' for junit:junit:jar is missing. # line 22, column 17
[ERROR] 'dependencies.dependency.version' for commons-cli:commons-cli:jar is missing. # line 26, column 17
root bom pom 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-dependencies-bom</name>
<url>http://myorg.org</url>
<properties>
<commons-cli.version>1.3</commons-cli.version>
<junit.version>3.8.1</junit.version>
</properties>
<modules>
<module>test-dependencies</module>
</modules>
</project>
test-dependencies/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>org.test</groupId>
<artifactId>test-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-parent-pom</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</project>
Maven project files referencing the bom 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>org.test.testapp</groupId>
<artifactId>test-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test-app</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
</dependencies>
</project>
There are 2 issues:
For importing of dependencies, the imported pom project (test-dependencies/pom.xml) should define the dependencies to import in a <dependencyManagement> section, not just <dependencies> as was done in your original sample.
The project that imports that pom needs to import the project that declares the dependencies (test-dependencies/pom.xml), not the parent pom.xml.
I fixed this by making the following changes.
test-dependencies/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>org.test</groupId>
<artifactId>test-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-parent-pom</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Maven project files referencing the bom 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>org.test.testapp</groupId>
<artifactId>test-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test-app</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>test-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
</dependencies>
</project>
After that, I was able to build and verify that the project importing the pom was bringing in the expected dependencies:
mvn dependency:tree
...
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # test-app ---
[INFO] org.test.testapp:test-app:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:compile
[INFO] \- commons-cli:commons-cli:jar:1.3:compile
Note that it still successfully pulled the version numbers as defined in properties from the parent pom.xml. This a perfectly valid way to structure the project. It just needed the 2 adjustments I described.

Maven not including dependencies

I have this in my 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.foo.ch1</groupId>
<artifactId>tutorials</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>tutorials</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>image-processing</artifactId>
<groupId>org.openimaj</groupId>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<artifactId>video-processing</artifactId>
<groupId>org.openimaj</groupId>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I have been following this:
http://www.openimaj.org/tutorial/processing-video.html
But for some reason the XuggleVideo classes and anything that has to do with video is not detected.
My project is divided in separate packages. I don't think that matters in maven anyway.
Is my pom.xml file setup wrong?
Use this repo <url>http://www.openimaj.org</url> instead <url>http://maven.apache.org</url>

Maven dependencies for Gson not being downloaded

I'm not that familiar with using Maven, so it is likely a user error in this case. My understanding of the elements in the POM file is that any "dependency" that is listed here will be retrieved from the Central Repository based upon the scope of the dependency. In my case, I'm attempting to use the Gson library from Google. It is located on the Central Repository and so it should be reachable by the Maven tool. I've executed "mvn -X compile" to determine if I can see the dependencies in the import. But I don't see them being downloaded during the compile. Any ideas as to what could be wrong with my configuration?
Below is my POM for my project.
<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.acumen.app</groupId>
<artifactId>CatalogConverter</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>CatalogConverter</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

Categories