cannot find symbol symbol: class DockerImageName - java

I have been trying to run an sbomtest that invokes a cyclonedx-cli docker image using test containers but the
import org.testcontainers.images.DockerImageName; doesn't work properly
Here is what I want the test to do for me
The SBOMTest class defines a GenericContainer field named cyclonedxCli that is annotated with the #Rule annotation. This container is based on the cyclonedx/cyclonedx-cli Docker image, and it maps a classpath resource at /path/to/sboms to the path /app/sboms in the container.
The testSBOMValidation method is a JUnit test that starts the cyclonedxCli container, runs the cyclonedx-cli validate command in the container to validate an SBOM file, and then stops the container.
The test method uses the execInContainer method of the GenericContainer class to run the cyclonedx-cli command in the container, and it stores the command's output and exit code in the result variable.
The test method then uses the assertThat method from the AssertJ library to assert that the command's exit code is zero. This indicates that the command completed successfully.
Finally, the test method stops the cyclonedxCli container using the stop method of the GenericContainer class.
Below is my SBOMTest class and my pom.xml. Why doesn't my test pass?
package com.mkyong.hashing;
import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.images.DockerImageName;
import org.testcontainers.images.DockerImageName;
import static org.assertj.core.api.Assertions.assertThat;
public class SBOMTest {
public static final DockerImageName CYCLONEDX_CLI_IMAGE = DockerImageName.parse("cyclonedx/cyclonedx-cli:v0.24.2");
#Rule
public GenericContainer<?> cyclonedxCli = new GenericContainer<>(CYCLONEDX_CLI_IMAGE)
.withClasspathResourceMapping("/home/ntn/workdir", "/app/sboms", BindMode.READ_ONLY);
#Test
public void testSBOMValidation() throws Exception {
// Start the container
cyclonedxCli.start();
// Validate the SBOM file using the cyclonedx-cli command
String sbomFileName = "/home/ntn/workdir/julian.json";
Container.ExecResult result = cyclonedxCli.execInContainer("cyclonedx-cli", "validate", "--input-file", sbomFileName, "--fail-on-errors");
String stdout = result.getStdout();
// Assert that the command returned a zero exit code
assertThat(result.getExitCode()).isZero();
// Stop the container
cyclonedxCli.stop();
}
}
Below is 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>com.mkyong.hashing</groupId>
<artifactId>java-project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>java-project</name>
<url>http://maven.apache.org</url>
<properties>
<!-- https://maven.apache.org/general.html#encoding-warning -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<!-- Attach the shade into the package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mkyong.hashing.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- fat-jar -->
<!-- https://books.sonatype.com/mvnex-book/reference/customizing-sect-custom-packaged.html -->
<!--
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.mkyong.hashing.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>simple-command</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</project>
I was expecting the test to pass successfully
The following are the error logs
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.mkyong.hashing:java-project >-------------------
[INFO] Building java-project 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # java-project ---
[INFO] Deleting /home/ntn/outreachytest/maven-examples/java-project/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # java-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/ntn/outreachytest/maven-examples/java-project/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # java-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/ntn/outreachytest/maven-examples/java-project/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # java-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/ntn/outreachytest/maven-examples/java-project/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # java-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/ntn/outreachytest/maven-examples/java-project/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[6,33] cannot find symbol
symbol: class DockerImageName
location: package org.testcontainers.images
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[7,33] cannot find symbol
symbol: class DockerImageName
location: package org.testcontainers.images
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[10,35] package org.assertj.core.api does not exist
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[10,1] static import only from classes and interfaces
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[14,25] cannot find symbol
symbol: class DockerImageName
location: class com.mkyong.hashing.SBOMTest
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[14,63] cannot find symbol
symbol: variable DockerImageName
location: class com.mkyong.hashing.SBOMTest
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[18,78] cannot find symbol
symbol: variable BindMode
location: class com.mkyong.hashing.SBOMTest
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[27,18] package Container does not exist
[INFO] 8 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.466 s
[INFO] Finished at: 2022-12-26T06:24:21+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project java-project: Compilation failure: Compilation failure:
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[6,33] cannot find symbol
[ERROR] symbol: class DockerImageName
[ERROR] location: package org.testcontainers.images
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[7,33] cannot find symbol
[ERROR] symbol: class DockerImageName
[ERROR] location: package org.testcontainers.images
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[10,35] package org.assertj.core.api does not exist
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[10,1] static import only from classes and interfaces
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[14,25] cannot find symbol
[ERROR] symbol: class DockerImageName
[ERROR] location: class com.mkyong.hashing.SBOMTest
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[14,63] cannot find symbol
[ERROR] symbol: variable DockerImageName
[ERROR] location: class com.mkyong.hashing.SBOMTest
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[18,78] cannot find symbol
[ERROR] symbol: variable BindMode
[ERROR] location: class com.mkyong.hashing.SBOMTest
[ERROR] /home/ntn/outreachytest/maven-examples/java-project/src/test/java/com/mkyong/hashing/SBOMTest.java:[27,18] package Container does not exist
[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

Related

Maven: package io.swagger.annotations does not exist

I want to document my project with swagger. I add swagger annotations and io.springfox dependencies to my project but when I run mvn clean package I have a lot of errors:
PS D:\parent-project> mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent-project [pom]
[INFO] module-common-lib [jar]
[INFO] module1 [jar]
[INFO] module2 [jar]
[INFO]
[INFO] ------------< parent-project:parent-project >-------------
[INFO] Building parent-project 0.0.1-SNAPSHOT [1/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # parent-project ---
[INFO]
[INFO] -------< parent-project:module-common-lib >-------
[INFO] Building module-common-lib 0.0.1-SNAPSHOT [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # module-common-lib ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # module-common-lib ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\parent-project\module-common-lib\src\main\resources
[INFO] skip non existing resourceDirectory D:\parent-project\module-common-lib\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) # module-common-lib ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\parent-project\module-common-lib\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[7,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[9,2] cannot find symbol
symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[8,2] cannot find symbol
symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[7,2] cannot find symbol
symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[7,2] cannot find symbol
symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[31,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[40,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[49,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[13,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.HelloWorldResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[13,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.ResponseSimple
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[14,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[23,10] cannot find symbol
symbol: class ApiModelProperty
location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[INFO] 19 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent-project 0.0.1-SNAPSHOT ............... SUCCESS [ 0.156 s]
[INFO] module-common-lib ................... FAILURE [ 1.530 s]
[INFO] module1 ..................... SKIPPED
[INFO] module2 0.0.1-SNAPSHOT ...... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.910 s
[INFO] Finished at: 2018-09-18T09:39:17+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project module-common-lib: Compilation failure: Compilation failure:
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[7,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[9,2] cannot find symbol
[ERROR] symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[8,2] cannot find symbol
[ERROR] symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[7,2] cannot find symbol
[ERROR] symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[7,2] cannot find symbol
[ERROR] symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[31,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[40,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseInfo.java:[49,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldResponse.java:[13,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.HelloWorldResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/ResponseSimple.java:[13,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.ResponseSimple
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[14,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.java:[23,10] cannot find symbol
[ERROR] symbol: class ApiModelProperty
[ERROR] location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :module-common-lib
In this project both module1 and module2 use the common-lib to use JSON as a response type and to create the documentation with swagger.
Structure Project:
parent-project
pom.xml
module-common-lib
pom.xml
src/main/java
module1
src/main/java
src/main/resources
pom.xml
module2
src/main/java
src/main/resources
pom.xml
Pom.xml - parent-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">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<packageClassifier>exec</packageClassifier>
<spring-boot.version>1.5.9.RELEASE</spring-boot.version>
<spring-cloud.version>1.4.4.RELEASE</spring-cloud.version>
<springfox-swagger.version>2.6.1</springfox-swagger.version>
</properties>
<dependencyManagement>
<dependencies>
.....
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module-common-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
Pom.xml - module-common-lib
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
</project>
One of the classes with swagger annotations (the other classes have the same annotations but diferent code):
import java.io.Serializable;
import java.util.Optional;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#ApiModel
public class ResponseSimple implements Serializable {
transient private static final long serialVersionUID = 5106222175899418836L;
private ResponseInfo responseInfo = new ResponseInfo();
#ApiModelProperty(notes = "Response info")
public ResponseInfo getResponseInfo() {
return responseInfo;
}
public void setResponseInfo(ResponseInfo responseInfo) {
this.responseInfo = responseInfo;
}
#Override
public String toString() {
return Optional.of(responseInfo).map(ri -> ri.toString()).orElse("");
}
}
I have Maven 3.5.4
Does anyone know why it does not work?
In your module-common-lib/pom.xml file, you only refer to the io.springfix:springfox-swagger2 dependency in the <dependencyManagement> element.
In the child POM, the <dependencies> element does not need to be inside a <dependencyManagement> element, since you are consuming the dependency (not just managing its version, scope, exclusions and so on for subsequent consumption - which is what the parent POM does).
Basically the fact that the dependency io.springfox:springfox-swagger2 is only in the <dependencyManagement> section means that it (and, more importantly, also its transitive dependency io.swagger:swagger-annotations which contains the io.swagger.annotationspackage) is not added to the compilation classpath.
You can verify this by running mvn dependency:build-classpath to see the classpath that Maven builds.
The fix is to remove the lines <dependencyManagement> and </dependencyManagement> in module-common-lib/pom.xml (but NOT from parent-project/pom.xml, where the element serves its intended purpose).

Aspectj class is not found by test class when running test with maven

I have created a test for my aspectj class.
When I execute my test it works fine to "Run as TestNG" from Eclipse.
Then when I execute it in maven:
mvn clean test
I get the following error:
[15:15] [eraonel/git/java-runtime-stats] -> mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building java-runtime-stats 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # java-runtime-stats ---
[INFO] Deleting /repo/eraonel/git/java-runtime-stats/target
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (default) # java-runtime-stats ---
[INFO] Executing tasks
main:
[echo] BUILDING : /repo/eraonel/git/java-runtime-stats/src/main/java/com/company/commonlibrary/javaruntimestats/Version.java
[echo] BUILD 2018-10-24 13:18 UTC : /repo/eraonel/git/java-runtime-stats/src/main/java/com/company/commonlibrary/javaruntimestats/Version.java
[INFO] Executed tasks
[INFO]
[INFO] --- maven-java-formatter-plugin:0.6.1-threadsafe:format (default) # java-runtime-stats ---
[INFO] Using 'UTF-8' encoding to format source files.
[INFO] Number of files to be formatted: 21
[INFO] Successfully formatted: 1 file(s)
[INFO] Fail to format : 0 file(s)
[INFO] Skipped : 20 file(s)
[INFO] Approximate time taken: 0s
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # java-runtime-stats ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /repo/eraonel/git/java-runtime-stats/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # java-runtime-stats ---
[INFO] Compiling 15 source files to /repo/eraonel/git/java-runtime-stats/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # java-runtime-stats ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 11 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # java-runtime-stats ---
[INFO] Compiling 6 source files to /repo/eraonel/git/java-runtime-stats/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /repo/eraonel/git/java-runtime-stats/src/test/java/com/company/commonlibrary/javaruntimestats/aspects/DeprecatedMethodsAspectTest.java:[17,13] cannot find symbol
symbol: class DeprecatedMethodsAspect
location: class com.company.commonlibrary.javaruntimestats.aspects.DeprecatedMethodsAspectTest
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.127 s
[INFO] Finished at: 2018-10-24T15:18:08+02:00
[INFO] Final Memory: 33M/730M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile (default-testCompile) on project java-runtime-stats: Compilation failure
[ERROR] /repo/eraonel/git/java-runtime-stats/src/test/java/com/company/commonlibrary/javaruntimestats/aspects/DeprecatedMethodsAspectTest.java:[17,13] cannot find symbol
[ERROR] symbol: class DeprecatedMethodsAspect
[ERROR] location: class com.company.commonlibrary.javaruntimestats.aspects.DeprecatedMethodsAspectTest
[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
What am I missing here?
Why is the aspectj not compiled before the test case?
Is there a way to change this?
I used this example ( for the library part) to follow since I am creating a lib that should be used for other applications:
AspectJ: How to weave an aspect library into a Java project
TestClass:
/**
* Unit test to see if pointcut works as expected in ${#link DeprecatedMethodsAspect}
*/
public class DeprecatedMethodsAspectTest {
private DeprecatedMethodsAspect aspect;
private DeprecatedMethods deprecatedMethodsMock;
private DeprecatedMethodsApp app;
#BeforeClass
public void setUp() throws Exception {
app = new DeprecatedMethodsApp();
deprecatedMethodsMock = mock(DeprecatedMethods.class);
when(deprecatedMethodsMock.isActive()).thenReturn(true);
aspect = Aspects.aspectOf(DeprecatedMethodsAspect.class);
aspect.setDeprecatedMethods(deprecatedMethodsMock);
}
#Test
public void testSumIsMatched() throws Throwable {
app.sum(1, 2);
verify(deprecatedMethodsMock, times(1)).collect(any(JoinPoint.class));
}
#Test(description = " we should not gather information from methods annotated #Beta.")
public void testSubIsNotMatched() throws Throwable {
app.sub(2, 1);
verify(deprecatedMethodsMock, times(0)).collect(any(JoinPoint.class));
}
}
This is excerpt from my pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Compile scope dependencies -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${java.version}</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${java.version}</source>
<target>${java.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${java.version}</complianceLevel>
<encoding>${project.build.sourceEncoding}</encoding>
<!--<verbose>true</verbose> -->
<!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn> -->
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
You've included the aspectj-maven-plugin in <pluginManagement/> but you haven't included it in <plugins>
Try adding:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
</plugin>
</plugins>
under the <build/> element.
See also: Maven: What is pluginManagement?

Error to run a Maven with JUnit project in Eclipse

When I am trying to run a Maven with JUnit test in an eclipse project I've got this ERROR below:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building exemplo-maven 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # exemplo-maven ---
[INFO] Deleting C:\Users\vcamargo\workspace\exemplo-maven\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # exemplo-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # exemplo-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\vcamargo\workspace\exemplo-maven\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # exemplo-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # exemplo-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\vcamargo\workspace\exemplo-maven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # exemplo-maven ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.12.4/surefire-booter-2.12.4.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-surefire-common/2.12.4/maven-surefire-common-2.12.4.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain/2.0.9/maven-toolchain-2.0.9.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.470 s
[INFO] Finished at: 2017-02-27T10:08:30-03:00
[INFO] Final Memory: 19M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project exemplo-maven: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-surefire-plugin:jar:2.12.4 -> org.apache.maven.surefire:surefire-booter:jar:2.12.4: Failed to read artifact descriptor for org.apache.maven.surefire:surefire-booter:jar:2.12.4: Could not transfer artifact org.apache.maven.surefire:surefire-booter:pom:2.12.4 from/to central (https://repo.maven.apache.org/maven2): RSA premaster secret error: SunTls12RsaPremasterSecret KeyGenerator not available -> [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
Following my pom.xml below:
<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.algaworks.curso</groupId>
<artifactId>exemplo-maven</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<killAfter>-1</killAfter>
<mainClass>com.algaworks.curso.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
My main class:
package com.algaworks.curso;
public class Main {
public static void main(String[] args) {
System.out.println("Hello Maven");
}
}
And finally my test class:
package com.algaworks.curso;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class FibonacciTest {
#Test
public void deve_retornar_fibonacci_posicao_1() {
assertEquals(1L, 1L);
}
}
When I run my test class individually it runs perfect. And if I try to run a Maven project without test (goal: exec:java) it runs perfect too.
The error occur just when I try to run the Maven project with the JUnit test (goal: clean project).
Error says dependencies which are directly or indirectly used by surefire plug-in can not be resolved. i never had this error but, delete your maven-surefire-plugin folder from location : ".m2\repository\org\apache\maven\plugins"
and re-run the build which will automatically re-download all the plugin files.
make sure to have aback up of the folder before deleting so that you can analyse what were missing.
From the logs you've posted it seems like issue is not with your JUnit test cases, but with your maven not able to download few artifacts..In the repo I could see a maven surefire booter jar of required version..I guess there is some issue with network firewalls or connectivity...can we try reconnecting to network and then running a goal ?

Build Failure: Compiling Storm with Maven

I've been creating a storm topology and tested it with Eclipse, it's working. But now I'm testing it with a cluster, and when I package the jar it comes with this messages:
..................................................................
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Storm.Prova 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Storm.Prova ---
[INFO] Deleting /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/target
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) # Storm.Prova ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) # Storm.Prova ---
[INFO] Compiling 2 source files to /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.713s
[INFO] Finished at: Mon May 09 11:01:02 CEST 2016
[INFO] Final Memory: 18M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project Storm.Prova: Compilation failure: Compilation failure:
[ERROR] /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/src/main/java/Storm/practice/Storm/Prova/ProvaTopology.java:[101,28] error: incompatible types
[ERROR]
[ERROR] could not parse error message: required: int
[ERROR] found: Integer
[ERROR] /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/src/main/java/Storm/practice/Storm/Prova/ProvaTopology.java:108: error: no suitable constructor found for Values(String,String,int,int)
[ERROR] _collector.emit(new Values(tuple.getString(0),tuple.getString(1),z,tam));// id));
[ERROR] ^
[ERROR]
[ERROR] constructor Values.Values() is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/src/main/java/Storm/practice/Storm/Prova/ProvaTopology.java:[111,31] error: no suitable constructor found for Values(String,String,int,int)
[ERROR]
[ERROR] constructor Values.Values() is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] /home/amnor/Baixades/V0.10.0/workspace/Storm.Prova/src/main/java/Storm/practice/Storm/Prova/ProvaTopology.java:[115,30] error: no suitable constructor found for Values(String,String,int,int)
....
....................................................................
And a lot more, the weird thing is that it runs perfect on Eclipse and not showing any compiling error.
Any Idea why this is happening?
Thanks!
Here is my 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>Storm.practice</groupId>
<artifactId>Storm.Prova</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Storm.Prova</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-redis</artifactId>
<version>0.10.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>Storm.practice.Storm.Prova.ProvaTopology</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Storm.practice.Storm.Prova</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

Maven doesn't find org.junit even though it's in the dependencies

I wanted to add a test to my small project (please note I removed some bits from the code & changed package names, so if there's any error you see regarding this it might be not this ;)):
package my.pckg;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class SignedRequestCallbackTest {
#Before
public void setUp() throws Exception {
}
#After
public void tearDown() throws Exception {
}
#Test
public void testCorrectSignedRequest() {
assertTrue(false);
}
}
(I also tried to extend from TestCase in order to remove the static import but it didn't help)
After running mvn test it shows me an error that it couldn't find org.junit:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # server ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # server ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 9 source files to /Users/michael/Projects/fbmuc/server/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[4,27] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[6,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[7,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[8,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[14,9] cannot find symbol
symbol : class Before
location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[18,9] cannot find symbol
symbol : class After
location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[22,9] cannot find symbol
symbol : class Test
location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[24,12] cannot find symbol
symbol : method assertTrue(boolean)
location: class my.pckgSignedRequestCallbackTest
[INFO] 9 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.161s
[INFO] Finished at: Fri Feb 22 18:02:37 CET 2013
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project server: Compilation failure: Compilation failure:
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[4,27] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[4,4] static import only from classes and interfaces
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[6,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[7,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[8,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[14,9] cannot find symbol
[ERROR] symbol : class Before
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[18,9] cannot find symbol
[ERROR] symbol : class After
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[22,9] cannot find symbol
[ERROR] symbol : class Test
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[24,12] cannot find symbol
[ERROR] symbol : method assertTrue(boolean)
[ERROR] location: class my.pckgSignedRequestCallbackTest
[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
My pom.xml looks like 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>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TestServer</name>
<description>Test</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Facebook library -->
<dependency>
<groupId>com.restfb</groupId>
<artifactId>restfb</artifactId>
<version>1.6.11</version>
</dependency>
<!-- Gson: Java to Json conversion -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<!-- Tigase server snapshot -->
<dependency>
<groupId>tigase</groupId>
<artifactId>tigase-server</artifactId>
<version>5.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>tigase</id>
<name>Tigase repository</name>
<url>http://maven.tigase.org</url>
</repository>
<repository>
<id>tigase-snapshot</id>
<name>Tigase repository</name>
<url>http://build.xmpp-test.net/maven/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
mvn dependency:tree:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) # server ---
[INFO] my.pckg:server:jar:0.0.1-SNAPSHOT
[INFO] +- com.restfb:restfb:jar:1.6.11:compile
[INFO] +- com.google.code.gson:gson:jar:2.2.2:compile
[INFO] +- tigase:tigase-server:jar:5.2.0-SNAPSHOT:compile
[INFO] | +- tigase:tigase-utils:jar:3.4.1-SNAPSHOT:compile
[INFO] | \- tigase:tigase-xmltools:jar:3.4.3-SNAPSHOT:compile
[INFO] +- commons-codec:commons-codec:jar:1.7:compile
[INFO] \- junit:junit:jar:4.11:test
[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.240s
[INFO] Finished at: Fri Feb 22 18:07:55 CET 2013
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------
mvn version:
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/share/maven
Java version: 1.6.0_41, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: de_CH, platform encoding: MacRoman
OS name: "mac os x", version: "10.8.2", arch: "x86_64", family: "mac"
Please note that I'm not an expert in java nor in maven, just getting started (especially with maven).
From what I've seen from other articles and questions, I should have my tests within src/test/java and my "real" code within src/main/java - I have done it like this.
Also I removed once the whole ~/.m2/ folder and it still didn't work.
I also did run mvn test -X but it didn't help me. If I should post it please tell me so.
You shouldn't override your <sourceDirectory> setting in the POM's <build> element unless you have a good reason to. This attribute determines where Maven looks for non-test code. The default value for this attribute is src/main/java. The <testSourceDirectory> attribute sets the path to test code (this defaults to src/test/java. By setting the <sourceDirectory> to simply src, Maven considers that entire directory to contain main application code. Since the src directory contains src/test/java, Maven then tries to compile your test code as part of the main application.
This is significant because when compiling the main application (during the compile phase), Maven omits dependencies with test scope. Test code is compiled in a separate phase (the test-compile phase) after the main compile.
So since Maven tried to compile your test code as part of the main application, it omitted the junit dependency, and they weren't available on the classpath. The solution here is to simply not specify the <sourceDirectory> element in the POM.
By default , maven looks at these folders for java and test classes respectively - src/main/java and src/test/java
When the src is specified with the test classes under source and the scope for junit dependency in pom.xml is mentioned as test - org.unit will not be found by maven.
Just putting image to #matts Answer, so its easy for other to correct the problems.
<sourceDirectory>src</sourceDirectory>
just delete or comment this line present in pom.xml
<!-- <sourceDirectory>src</sourceDirectory> !-->
For explanation please go through #matt's answer

Categories