Issue with Pact Verify Provider Maven Plugin - java

Despite having the Pact file correctly placed in the folder, I am getting this exception:
You must specify the pactfile to execute for consumer.
Please help!
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>org.springframework</groupId>
<artifactId>gs-actuator-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.24</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.10</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven_2.11</artifactId>
<version>3.3.8</version>
<configuration>
<serviceProviders>
<!-- You can define as many as you need, but each must have a unique
name -->
<serviceProvider>
<name>DrivePOC1</name>
<!-- All the provider properties are optional, and have sensible
defaults (shown below) -->
<host>localhost</host>
<port>9000</port>
<path>/</path>
<consumers>
<consumer>
<name>ExpensePOC1</name>
<pactFile>Consumer_080517/target/pacts/ExtensePOC-DrivePOC.json</pactFile>
</consumer>
</consumers>
</serviceProviders>
</serviceProviders>
</configuration>
</plugin>
</plugins>
</build>
</project>
My Maven Pact Verify Goal Screenshot :
The error I get is:
[ERROR] Failed to execute goal
au.com.dius:pact-jvm-provider-maven_2.11:3.3.8:verify (default-cli)
on project gs-actuator-service: Execution default-cli of goal
au.com.dius:pact-jvm-provider-maven_2.11:3.3.8:verify failed:
You must specify the pactfile to execute for consumer 'consumer1'
(use <pactFile> or <pactUrl>) -> [Help 1]

Related

Maven Non-resolvable import POM

I'm using AWS ECS with EC2 instances and these instances are running java code. When trying to execute the code via maven I get the following error:
[ERROR] Non-resolvable import POM: Could not transfer artifact com.amazonaws:aws-java-sdk-bom:pom:1.11.106 from/to central (https://repo.maven.apache.org/maven2): transfer failed for https://repo.maven.apache.org/maven2/com/amazonaws/aws-java-sdk-bom/1.11.106/aws-java-sdk-bom-1.11.106.pom # line 16, column 19
I have seen a lot of posts mentioning that they needed to update settings.xml but in my case I do not have access to this as this code is being run in isolated docker container tasks. Is there anything I could add to the pom.xml file that would resolve this issues. Thanks.
Pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aws.example.sqs</groupId>
<artifactId>aws-sqs-examples</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Amazon SQS Examples</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.106</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Looks like its complaining about com.amazonaws:aws-java-sdk-bom:pom:1.11.106. This is a very OLD API and should not be used anymore.
It better practice to upgrade to AWS SDK for Java V2 and use a current POM that has:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.17.190</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Full 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>
<groupId>EC2J2Project</groupId>
<artifactId>EC2J2Project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.17.190</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ec2</artifactId>
</dependency>
</dependencies>
</project>

Maven not picking up the classes from dependency modules

In my spring-boot project there are two microservices, one config-server, and one naming server. It also has two modules which I am adding as a dependency in the microservices.
Below is the pom of the commons-new module which should be a dependency in my microservices.
<?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.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.highpeak.tlp</groupId>
<artifactId>commons-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>commons-new</name>
<description>Contains common modules needed by all the microservices</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And I am adding it as a dependency in my microservice.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.highpeak.tlp</groupId>
<artifactId>ybanq-auth-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ybanq-auth-manager</name>
<description>Manages the authentication process with ybanq</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.testSource>1.8</maven.compiler.testSource>
<maven.compiler.testTarget>1.8</maven.compiler.testTarget>
</properties>
<dependencies>
<dependency>
<groupId>com.highpeak.tlp</groupId>
<artifactId>commons-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.highpeak.tlp</groupId>
<artifactId>redis-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I try to build the microservice using the command mvn clean install, it is throwing compiler-error message.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ybanq-auth-manager: Compilation failure: Compilation failure:
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/controller/AuthController.java:[3,42] package com.highpeak.tlp.commons.exception does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/controller/AuthController.java:[4,37] package com.highpeak.tlp.commons.util does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerService.java:[3,42] package com.highpeak.tlp.commons.exception does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerService.java:[11,51] cannot find symbol
[ERROR] symbol: class DataException
[ERROR] location: interface com.highpeak.tlp.ybanqauthmanager.service.AuthManagerService
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerServiceImpl.java:[19,42] package com.highpeak.tlp.commons.exception does not exist
However, in IntelliJ editor those classes are accessible and Intellij is not showing the compiler error. But when I run the app in IntelliJ, it shows the same errors.
What is the mistake I am making? Since I added the module as dependency their classes should be available, right?
My system maven version is 3.5.4.
The Spring Boot plugin package up all dependency jars and pulls them into the jar your module builds. The structure of this jar is specifically for Spring Boot runnable applications and is not compatible with the normal jar structures, so you can't use a Spring Boot Application jar as maven dependency jar.
Remove spring boot plugin from submodule (common-new).
I had similar issue, but with gradle and found this Unresolved Dependency on package in subproject
Unfortunately, I don't know what is exact issue in "using" spring boot plugin in submodules/subprojects.

there is a way to detect errors on tomcat?

Hello everyone I have a java application (spring-boot) and I deployed it on tomcat9. The app appears on the tomcat manager and the first page of this app to connect appears correctly. But when I try to connect, the 404 error is declantiating.
I checked the Tomcat logs files, but no exceptions are thrown.
the 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>ValERef</groupId>
<artifactId>ValERef</artifactId>
<version>0.0.1-1</version>
<name>ValERef</name>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.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</java.version>
</properties>
<dependencies>
<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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>9.0.0.M1</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main</directory>
<includes>
<include>config.ini</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>spring-boot-tomcat</artifactId>
<version>3.7.0</version><!--$NO-MVN-MAN-VER$-->
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When i click the connect button nothing happens. But on eclipse the application worked very well (before the deployed on tomcat)

Maven clean install spring boot module runs webapp

When I run mvn clean install for my Maven module which is a spring boot application it kinda starts the spring boot web app withing the build process (and fails because of several errors)
This is my pom for that module:
<?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>com.application.coma</groupId>
<artifactId>coma-modules</artifactId>
<version>0.5.0</version>
</parent>
<artifactId>module-foo</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<dockerHost>http://localhost:2376</dockerHost>
<imageName>module-foo</imageName>
<dockerDirectory>.</dockerDirectory>
<imageTags>
<imageTag>${version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
</configuration>
</plugin>
</plugins>
</build>
</project>
What can I do - so it won't run the web app on every build?
Here is the parent pom for completeness:
<?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>
<artifactId>coma-platform</artifactId>
<groupId>com.application.coma</groupId>
<version>0.5.0</version>
</parent>
<artifactId>coma-modules</artifactId>
<packaging>pom</packaging>
<modules>
<module>module-foo</module>
<module>module-bar</module>
<module>module-findandreplace</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.application.coma</groupId>
<artifactId>coma-shared</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-docs</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-data-mongodb</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-security</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.session</groupId>-->
<!--<artifactId>spring-session</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-validation</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!--JSP relevant dependencies-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<generatedSourcesDirectory>
${project.build.directory}/generated-sources/
</generatedSourcesDirectory>
<annotationProcessors>
<annotationProcessor>
com.application.coma.shared.annotation.ComaModuleAnnotationProcessor
</annotationProcessor>
</annotationProcessors>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

How to run integration tests for a mavenised Android application?

I want to run some tests, which check, for example that activity A puts some piece of information into the intent, when it starts activity B.
Those tests require that there is Android infrastructure.
How can I implement them so that they can be run using Maven?
I tried
to use akquinet archetype for this and use a separate Mave project for integration tests, but it never worked (my Robolectric test is not exeuted) and
to run them in the same Maven project as the main app, which result in ClassNotFoundErrors caused by Robolectric (when I add Roboelectric to the dependencies, I can't mvn install my project because I get classpath-related errors for non-Robolectric classes).
Update 1 (23.08.2013): POM of the 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>my-product-parent</artifactId>
<version>1.3.0</version>
<packaging>pom</packaging>
<name>my-product - Parent</name>
<modules>
<module>my-product</module>
<module>my-product-it</module>
</modules>
<properties>
<platform.version> 4.1.1.4
</platform.version>
<android.plugin.version>3.6.0</android.plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<configuration>
<sdk>
<platform>16</platform>
</sdk>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
POM of the actual app 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>my-product-parent</artifactId>
<version>1.3.0</version>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>my-product</artifactId>
<version>1.4.0</version>
<packaging>apk</packaging>
<name>my-product - Application</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.5</powermock.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>some-library</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>commons</artifactId>
<version>2.5</version>
<exclusions>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.4</version>
</dependency>
<!-- Testing (start) -->
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<!-- Testing (end) -->
<!-- Google Maps (start) -->
<!--
<dependency>
<groupId>com.google.android.maps</groupId>
<artifactId>maps</artifactId>
<version>16_r3</version>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>6</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>6</version>
<type>jar</type>
</dependency>
<!-- Google Maps (end) -->
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
POM of the integration test 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>my-product-parent</artifactId>
<version>1.3.0</version>
</parent>
<artifactId>my-product-it</artifactId>
<packaging>apk</packaging>
<name>my-product-it - Integration tests</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-product</artifactId>
<type>apk</type>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-product</artifactId>
<type>jar</type>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
</dependency>
<!-- Make sure this (robolectric dependency) is below the android dependencies -->
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.0-RC4</version>
<exclusions>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
<exclusion>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
</exclusion>
<!--
<exclusion>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</exclusion>
-->
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<test>
<!--<skip>true|false|auto</skip> -->
<!--<instrumentationPackage>packageName</instrumentationPackage> -->
`
<!--<instrumentationRunner>className</instrumentationRunner> -->
<!--<debug>true|false</debug> -->
<!--<coverage>true|false</coverage> -->
<!--<logonly>true|false</logonly> avd -->
<!--<testsize>small|medium|large</testsize> -->
<createReport>true</createReport>
<classes>
<class>com.mycompany.cb.android.test.AcceptInvitationActivityTest</class>
</classes>
<!--<classes> -->
<!--<class>your.package.name.YourTestClass</class> -->
<!--</classes> -->
<!--<packages> -->
<!--<package>your.package.name</package> -->
<!--</packages> -->
</test>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
Do checkout Github Android App source code. https://github.com/github/android
This project has a very good maven setup with integration-tests. They use Roboguice and maven-android-plugin
Hope it helps.
This project integrates a lot of testing tools as well as code quality tools: https://github.com/stephanenicolas/Quality-Tools-for-Android
I wrote a bash script that generates a mavenized android project with robolectric, spoon and robotium configured: https://github.com/marsucsb/mvn-android-project

Categories