Issue
I am new to maven and junit. I have tried to build a maven project through which I want to try the kubernetes official java client api examples. While compiling the pom.xml file encountered an error. I am trying to run the maven project using command line. In order to compile the pom.xml file I have used "mvn clean package install"
<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>ocp</groupId>
<artifactId>DemoTest</artifactId>
<version>14.0.1</version>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-plugin-version>1.0.0</maven-plugin-version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-proto</artifactId>
<version>14.0.0</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
</project>
Error:-
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[3,28] package io.kubernetes.client does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[4,28] package io.kubernetes.client does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[5,28] package io.kubernetes.client does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[6,33] package io.kubernetes.client.apis does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[7,35] package io.kubernetes.client.models does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[8,35] package io.kubernetes.client.models does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[9,33] package io.kubernetes.client.util does not exist
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[14,64] cannot find symbol
symbol: class ApiException
location: class ocp.App
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[15,9] cannot find symbol
symbol: class ApiClient
location: class ocp.App
[ERROR] /mnt/d/junit/test/new/DemoTest/src/main/java/ocp/App.java:[15,28] cannot find symbol
symbol: variable Config
location: class ocp.App
Please suggest what have I missed.
Solution
You don't need dependency of type "pom" - just remove this line and try to rebuild.
Maven will try to "bring" the dependency (by downloading it from the centralized repo) to your classpath. In java dependencies like this are jars. So that's the problem I believe
Also, compile
is a default scope anyway, so you can omit it.
In addition, project.version points on the version of your product, probably you want a specific version of the dependency, like 14.0.1 (the last version available in maven central)
It might be a coincidence, but your own project also has the same version (14.0.1) exactly. I don't see a reason to do so, you can start your project with your own version that has nothing to do with k8s java client's version)
For example you can use 1.0-SNAPSHOT
An example of the dependency definition (of k8s java client as you've stated in the question title) is:
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>14.0.1</version>
</dependency>
The rest of the dependencies in the presented pom also should be fixed in a similar way.
Answered By - Mark Bramnik
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)