Spring Boot application build with Maven encounters Java Version Issue - java

I was trying to build an application using maven build.It was returning this build failure even though I have placed my pom.xml file is in-place.
I have configure my pom with out any issue.But I can see that there is some error returning related to schema.But don't have much information on that
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.amazon:amazon:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-test:jar -> duplicate declaration of version (?) # line 65, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyApplication 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) # amazon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) # amazon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /Users/Arun/Documents/SpringBoot/MyApplication/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.051 s
[INFO] Finished at: 2018-06-09T08:00:55-07:00
[INFO] Final Memory: 25M/220M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project amazon: Fatal error compiling: invalid target release: 1.8.0_73 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Below is the pom.xml which I am using as of now.
<?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.amazon</groupId>
<artifactId>amazon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyApplication</name>
<description>Demo project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.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.0_73</java.version>
<start-class>com.amazon.service.MyApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

According to your logs:
Fatal error compiling: invalid target release: 1.8.0_73
You might be using an inferior JDK version (1.7 for example) to compile your project to a higher target version (1.8.0_73 in your case).
Try installing JDK 1.8 and make your JAVA_HOME environment variable point to it.
Generally you should make sure the source JDK and target JDK are matching between your pom.xml file and your JAVA_HOME environment variable.

You can try maven compiler plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

Remove the duplicate dependency added
<artifactId>spring-boot-starter-test</artifactId>
And
Try pointing to JDK 1.8 in project build path and make your JAVA_HOME environment to this

In general the minor release number (for java) is not configured in pom.xml. Only major release number will be require.
Try to change 1.8.0_73 to 1.8.
To understand the java version system please visit this link.

Looking in your maven output, it is clear that you have a duplicate dependency declaration. Moreover, it is clear that the duplicate dependency is the org.springframework.boot:spring-boot-starter-test.
What is the process of solving the issue and removing this WARNING:
Look VERY carefully your pom.xml. You probably have declared the dependency twice.
An other cause of this warning might be that a dependency is declared twice, but with different versions. The solution, again, is to delete the dependency for one of them.
Command mvn dependency:tree -Dverbose might be useful.
Finally, after writing the above process, I looked in the pom.xml file you posted in your question and found that you have declared the following dependency twice (line:54 and line:65).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
As far as I am concerned, this library is used for testing purposes only. If this is true, depending on your requirements, you should keep only the dependency in line 54 and the warning will be removed.

Related

Spring Application not deploying on Heroku " ERROR: Build Failure"

Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud. I am deploying My Spring application on Heroku and it is giving a build failure error.
It's working on localhost but don't know why it is not deploying, please resolve my problem. any help can be appreciated, Thanks.
Error File:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 25 source files to /tmp/build_d30a8927/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.201 s
[INFO] Finished at: 2022-10-14T18:42:07Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project MyApp: Fatal error compiling: invalid target release: 17 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
! ERROR: Failed to build app with Maven
We're sorry this build is failing! If you can't find the issue in application code,
please submit a ticket so we can help: https://help.heroku.com/
! Push rejected, failed to compile Java app.
! Push failed
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.spring.demo</groupId>
<artifactId>MyApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MyApp</name>
<description>Demo project for MyApp</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Create a file called system.properties below the pom.xml file and write these:
java.runtime.version=17
maven.version=3.6.2
It was not working because your java version is 17 and Heroku's using default java version which is different.

Java 11 without modularity: package does not exist while it is added as maven dependency

I have three very simple applilcations. One is COMMON which I will center security configs, other with ZUUL feature and the third is a EUREKA SERVER. Both are Spring Boot and Java 11. Although I am using Java 11 I am not reling on modularity (as far as I know it will not make sense use modularity feature with Spring Boot).
When I run all three in Eclipse I successfully can run the server, common and zuul in that sequence. When I try to maven build I get the error mentioned in subject.
The immediate explanation would be "you don't have common in zuul classpath". Well, as far as I check I do have common in zuul classpath. I am wondering if there is any extra config because I am using Java 11 but not using modularaty.
By saying I am using Java 11 but not modularity I mean, I have Java 11 but I don't have module-info.java at all in any of the three projects.
Checking in .m2 folder and unzip the common.jar I do see the class complained.
Zuul project pom:
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>zuul</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zuul</name>
<description>Zuul project</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.test</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</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>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Evidence that common is the maven dependences
Error during mvn clean install:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< com.test:zuul >----------------------------
[INFO] Building zuul 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) # zuul ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # zuul ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\_d\WSs\soteste\zuul\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[14,32] package com.test.common.security does not exist
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[21,17] cannot find symbol
symbol: class JwtConfig
location: class com.test.zuul.security.SecurityTokenConfig
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[46,16] cannot find symbol
symbol: class JwtConfig
location: class com.test.zuul.security.SecurityTokenConfig
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[47,23] cannot find symbol
symbol: class JwtConfig
location: class com.test.zuul.security.SecurityTokenConfig
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.778 s
[INFO] Finished at: 2019-03-21T14:23:23-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project zuul: Compilation failure: Compilation failure:
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[14,32] package com.test.common.security does not exist
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[21,17] cannot find symbol
[ERROR] symbol: class JwtConfig
[ERROR] location: class com.test.zuul.security.SecurityTokenConfig
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[46,16] cannot find symbol
[ERROR] symbol: class JwtConfig
[ERROR] location: class com.test.zuul.security.SecurityTokenConfig
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/com/test/zuul/security/SecurityTokenConfig.java:[47,23] cannot find symbol
[ERROR] symbol: class JwtConfig
[ERROR] location: class com.test.zuul.security.SecurityTokenConfig
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
The class complained is in the jar
*** Edited
Common pom
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>common</name>
<description>Zuul project</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
That's because the common project is a Spring Boot Application (I see the BOOT-INF folder inside the generated jar).
From Use a Spring Boot Application as a Dependency documentation:
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 a dependency.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
Here is an example:
The first jar is build as dependency-able, the second one is Spring Boot executable.
That Eclipse is able to resolve Eclipse projects of the currently open workspace as Maven dependencies into other projects is a specialty of Eclipse.
If you execute Maven on command-line or from within Eclipse you leave the sphere of Eclipse and use plain Maven. Plain Maven (even the in Eclipse integrated Maven) does not know about Eclipse projects, it only knows the artifacts available in your local and the configured remote repositories.
Therefore the correct approach in your case is to first execute mvn install on your common project. This installs common into your local repo and makes it available to Maven.
Afterwards you can execute mvn clean install on your zuul project.

Why java pacakges are not loading in intelliJ ideda

I followed a tutorial and get this dependency file in maven project in intelliJ IDEA 2018.3
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>kafka.sample.firstProject</groupId>
<artifactId>kafka-first-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<kafka.version>2.1.0</kafka.version>
</properties>
<build>
<plug
ins>
<!-- Maven Compiler Plugin-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Apache Kafka Clients-->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.0</version>
</dependency>
<!-- Apache Kafka Streams-->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>2.0.0</version>
</dependency>
<!-- Apache Log4J2 binding for SLF4J -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>
<!-- JUnit5 Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!-- JUnit 5 Jupiter Engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!-- JUnit 5 Jupiter Parameterized Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
but whenever i try to run my build it throws this:
Error:(3, 41) java: package org.apache.kafka.clients.producer does not
exist and so on ...
Even after trying to run maven build still the problem persist.
Believe it or not i have get stuck in this problem from last many days.
Edit:
As #Parsecer asked to show maven build log, i found that there is an error as well
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building kafka-first-sample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.329 s
[INFO] Finished at: 2019-02-20T09:10:30+05:00
[INFO] Final Memory: 7M/34M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): No such host is known (repo.maven.apache.org) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
Process finished with exit code 1
1) Check settings of IntelliJ by Ctrl-Alt-S. Type 'Maven' and see if you have proper Maven distribution (not the bundled one).
2) Refresh your Maven project from the right hand side of IntelliJ window.
This happens due to several issues which normally fixed after an IDE restart. Well you can try several things,
Do a maven reimport
Do a maven Download sources and documentation
And restart the JIdea IDE
You can try to use a latest maven version and see also.
My System was behind a Proxy which not allowing me to get these packages. I remove the proxy and now it is working fine.

Running project in IntelliJ

I have one application based on Maven + Spring.
It's a Java web application using java.
this is the pom.xml i'm using:
<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.alfred</groupId>
<artifactId>alfred</artifactId>
<version>v.0.1-CID.Fase.II.Edesk-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<name>ALFRED</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<!-- Dependencia para Spring DATA JPA con base de datos -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Para implementar las conexiones a la base de datos MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- version>5.1.35</version -->
</dependency>
<!-- Para implementar el servicio REST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- http://mvnrepository.com/artifact/com.google.code.gson/gson -->
<!-- Paquete que permite convertir el contenido de una respuesta en texto
plano JSON a objetos Java. -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<!-- Para implementar cliente REST con Template -->
<!-- dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId>
</dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- Para implementar las plantillas HTML con thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity3 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
</dependency>
<!-- Para poder implementar los clientes de los servicios REST -->
<dependency>
<groupId>com.squareup.retrofit</groupId>
<artifactId>retrofit</artifactId>
<version>1.7.1</version>
</dependency>
<!-- Para escapar HTML en las llamadas a la API de IMDB -->
<!-- http://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Java Mail API -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-ldap -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<!-- Librería para tratar con excels -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId>
<configuration> DO NOT include log4j.properties file in your Jar <excludes>
<exclude>**/log4j.properties</exclude> </excludes> <archive> </archive> </configuration>
</plugin> -->
</plugins>
</build>
</project>
When I do the clean, generate resources and install appear this error and not start working
"C:\Program Files\Java\jdk1.8.0_151\bin\java"
-Dmaven.multiModuleProjectDirectory=C:\Users\spainasg\Documents\CID_UAT
-Dmaven.home=C:\Users\spainasg\Downloads\apache-maven-3.5.2-bin\apache-maven-3.5.2 -Dclassworlds.conf=C:\Users\spainasg\Downloads\apache-maven-3.5.2-bin\apache-maven-3.5.2\bin\m2.conf
-Dfile.encoding=UTF-8 -classpath C:\Users\spainasg\Downloads\apache-maven-3.5.2-bin\apache-maven-3.5.2\boot\plexus-classworlds-2.5.2.jar
org.codehaus.classworlds.Launcher -Didea.version=2017.2.6 --offline -s
C:\Users\spainasg.m2\settings.xml
-Dmaven.repo.local=C:\Users\spainasg.m2\repository clean generate-resources install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for
com.alfred:alfred:war:v.0.1-CID.Fase.II.Edesk-SNAPSHOT
[WARNING] Detected profiles.xml alongside com.alfred:alfred:v.0.1-CID.Fase.II.Edesk-SNAPSHOT, this file is no
longer supported and was ignored, please use the settings.xml instead
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ALFRED v.0.1-CID.Fase.II.Edesk-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.maven.plugins:maven-install-plugin:jar:2.5.2 is missing, no
dependency information available
[WARNING] The POM for com.oracle:ojdbc14:jar:10.2.0.4.0 is missing, no dependency information available
[WARNING] The POM for org.thymeleaf.extras:thymeleaf-extras-springsecurity3:jar:2.1.2.RELEASE
is missing, no dependency information available
[WARNING] The POM for org.apache.poi:poi:jar:3.16 is missing, no dependency information available
[WARNING] The POM for org.apache.poi:poi-ooxml-schemas:jar:3.16 is missing, no dependency information available
[WARNING] The POM for com.github.virtuald:curvesapi:jar:1.04 is missing, no dependency information available
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # alfred ---
[INFO] Deleting C:\Users\spainasg\Documents\CID_UAT\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # alfred ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 90 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # alfred ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 174 source files to C:\Users\spainasg\Documents\CID_UAT\target\classes
[WARNING] /C:/Users/spainasg/Documents/CID_UAT/src/main/java/com/edesk/controladorGUI/GestionServicioAprobadorController.java:
C:\Users\spainasg\Documents\CID_UAT\src\main\java\com\edesk\controladorGUI\GestionServicioAprobadorController.java
uses unchecked or unsafe operations.
[WARNING] /C:/Users/spainasg/Documents/CID_UAT/src/main/java/com/edesk/controladorGUI/GestionServicioAprobadorController.java:
Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # alfred ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\spainasg\Documents\CID_UAT\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # alfred ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) # alfred ---
[WARNING] The POM for org.apache.maven.surefire:maven-surefire-common:jar:2.17 is missing,
no dependency information available
[WARNING] The POM for org.apache.maven.surefire:surefire-api:jar:2.17 is missing, no
dependency information available
[WARNING] The POM for org.apache.maven:maven-toolchain:jar:2.0.9 is missing, no dependency information available
[WARNING] The POM for org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.2 is
missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.961 s
[INFO] Finished at: 2017-11-30T09:45:30+01:00
[INFO] Final Memory: 29M/233M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test
(default-test) on project alfred: Execution default-test of goal
org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed:
Plugin org.apache.maven.plugins:maven-surefire-plugin:2.17 or one of
its dependencies could not be resolved: The following artifacts could
not be resolved:
org.apache.maven.surefire:maven-surefire-common:jar:2.17,
org.apache.maven.surefire:surefire-api:jar:2.17,
org.apache.maven:maven-toolchain:jar:2.0.9,
org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.2,
org.codehaus.plexus:plexus-utils:jar:1.1: Cannot access central
(https://repo.maven.apache.org/maven2) in offline mode and the
artifact org.apache.maven.surefire:maven-surefire-common:jar:2.17 has
not been downloaded from it before. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
[ERROR] Maven execution terminated abnormally (exit code 1)
I'm using IntelliJ, but have the same error using Eclipse.
The aplications are working offline.
Any idea for this solution?
Try to add all your missing dependencies.
[WARNING] The POM for org.apache.maven.surefire:maven-surefire-common:jar:2.17 is missing, no dependency information available
[WARNING] The POM for org.apache.maven.surefire:surefire-api:jar:2.17 is missing, no dependency information available
[WARNING] The POM for org.apache.maven:maven-toolchain:jar:2.0.9 is missing, no dependency information available
[WARNING] The POM for org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.2 is missing, no dependency information available

Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar

So I was trying to go ahead and create a .ear file for an existing maven project and further deploy it on WebLogic server. For the same, I went ahead to create the WAR,JAR and the EAR module and followed these steps for it -
Right click on parent project, select new, select maven module, Named it as projectnameJARModule and then finished the wizard.
Did the same process for creating a projectnameWARModule and a projectnameEARModule module. Once they were made, I added the WAR and the JAR modules as dependencies to the EAR module.Further, I went ahead to install the maven modules by Right Clicking on the projectnameWARModule folder and chose Run As - Maven Install. Upon this, I get the following error in the console (Full console log below) -
T E S T S
-------------------------------------------------------
Running org.CADJARModule.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # CADJARModule ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] projectname ............................................... SUCCESS [ 0.957 s]
[INFO] projectnameJARModule ...................................... FAILURE [ 33.425 s]
[INFO] projectnameWARModule Maven Webapp ......................... SKIPPED
[INFO] projectnameEARModule ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.806 s
[INFO] Finished at: 2015-12-01T18:16:20+05:30
[INFO] Final Memory: 9M/126M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project projectnameJARModule: Error assembling JAR: For artifact {org.glassfish.jersey.containers:jersey-container-servlet-core:null:jar}: The version cannot be empty. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :projectnameJARModule
Any idea how do I get rid of this? Many Thanks
Following is the pom.xml for the Parent Module -
<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>Project_name</groupId>
<artifactId>Project_name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Project_name</name>
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version> <!-- Put here the version of your Java EE app, in my case 7.0 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<jersey.version>2.16</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>Project_nameJARModule</module>
<module>Project_nameWARModule</module>
<module>Project_nameEARModule</module>
</modules>
</project>
Following is the pom.xml for the WAR Module-
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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>
<parent>
<groupId>Projectname</groupId>
<artifactId>Projectname</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>ProjectnameWARModule</groupId>
<artifactId>ProjectnameWARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ProjectnameWARModule 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>ProjectnameWARModule</finalName>
</build>
</project>
Following is the pom.xml for my JAR module -
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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>
<parent>
<groupId>Project_Name</groupId>
<artifactId>Project_Name</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>CADJARModule</groupId>
<artifactId>CADJARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CADJARModule</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Let me clarify: the dependencyManagement section provide dependencies governance to the same POM where it is defined and to children/modules Maven projects.
However, declaring a dependency in the dependencyManagement section doesn't mean Maven will use it, it's just an hint in case Maven will use it so that if a certain version is missing in the dependencies section, Maven will look it up in the dependencyManagement section. If none is found then, an error will be generated (Maven couldn't know which version to resolve for a certain dependency).
Hence, good to have the dependencyManagement section for governance, but it should always define versions of each dependency, otherwise it would be a missed opportunity and make your build more error-prone.
If you need all of the declared dependencies and only in the scope of the same declaring POM, then you can actually avoid to have a dependenciesManagement section at all and just have your dependencies section providing versions for each declared dependency.
In this case, you are using a dependenciesManagement section in your parent POM (I see it has modules), you should then check if in the jar module the same dependency is declared (if required), otherwise it will not be used during its build. Moreover, you should also check whether another dependenciesManagement section is declared in the concerned module and re-declaring the same dependency again without version.
Some additional helps can be provided by:
Running your Maven build using the -e -X flags
Running mvn dependency:tree -Dincludes=<concerned_group_id_here>
Last change option, run your build as mvn dependency:purge-local-repository clean install, which can work in case of corrupted cache (error should be different though)

Categories

Resources