Spring Boot Microservice Deployment issue on Google Cloud - spring

I have created a simple microservice using spring boot and want to deploy on google cloud for which I have created one billing account.But when I'am trying to deploy microservice to google cloud using appengine:deploy .It shows following error -
[INFO] GCLOUD: ERROR: (gcloud.app.deploy) Error Response: [8] Flex operation projects/springbootmicroservices-302707/regions/asia-northeast2/operations/f958224e-d3b7-4b27-ac1d-513896ce934b error [RESOURCE_EXHAUSTED]: An internal error occurred while processing task /app-engine-flex/insert_flex_deployment/flex_create_resources>2021-01-24T07:39:53.754Z3254.hq.2: The requested amount of instances has exceeded GCE's default quota. Please see https://cloud.google.com/compute/quotas for more information on GCE resources
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:44 min
[INFO] Finished at: 2021-01-24T13:10:56+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:2.0.0-rc2:deploy (default-cli) on project springBoot: Flexible application deployment failed: com.google.cloud.tools.appengine.cloudsdk.process.ProcessHandlerException: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1 -> [Help 1]
[ERROR] .
app.yaml
runtime: java
env: flex
runtime_config:
jdk: openjdk8
handlers:
- url: /.*
script: this field is required, but ignore.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springBoot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.0.0-rc2</version>
<configuration>
<deploy.projectId>springbootmicroservices-302707</deploy.projectId>
<deploy.version>03</deploy.version>
<cloudSdkHome>C:\Users\utkar\AppData\Local\Google\Cloud SDK\google-cloud-sdk</cloudSdkHome>
<cloudSdkVersion>324.0.0</cloudSdkVersion>
<!-- <appId>sample-project-vijay</appId> -->
<!-- <deployables>
<param>target/Services-0.0.1/WEB-INF/appengine-web.xml</param>
</deployables> -->
</configuration>
</plugin>
</plugins>
</build>
</project>
controller class
#RestController
public class MainController {
#GetMapping(value = "utkarsh/details")
public Student home() {
Student s=new Student();
s.setAge(24);
s.setCompany("abc");
s.setGender("Male");
s.setLocation("Meerut");
s.setName("Utkarsh Sharma");
return s;
}
}
Please resolve the issue.Thanks in advance

This is from your error message:
[RESOURCE_EXHAUSTED]: An internal error occurred while processing task /app-engine-flex/insert_flex_deployment/flex_create_resources>2021-01-24T07:39:53.754Z3254.hq.2: The requested amount of instances has exceeded GCE's default quota. Please see https://cloud.google.com/compute/quotas for more information on GCE resources
I would follow that link and follow the steps to Checking your quota - that would be valuable info to understand the problem.

Related

How to skip failsafe execution for pom packaging?

I wanted to configure failsafe with failIfNoTests in a parent pom because we are currently upgrading Spring Boot in our microservices, and tests might not be properly detected if they are still using JUnit 4 (you need to migrate them or use junit-vintage).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
The problem however is that this causes the plugin to also run in the build of the parent pom. I don’t want to put this in <pluginManagement> because I want to make sure that the plugin is running in child projects (otherwise they still have to declare the plugin and it might be forgotten).
Is there a way to prevent the failsafe plugin from running with pom packaging?
Note that I did the same with surefire, but there is no issue with that one as its goals are managed by Maven’s default lifecycle, which depends on the pom packaging. However for failsafe the goals are declared in spring-boot-starter-parent’s <pluginManagement> so it applies for all packaging types.
For the moment, I did it with a profile based on this question, but I find this quite dirty:
<profile>
<id>disable-integration-tests-for-pom-packaging</id>
<!-- this profile detects that we are not building an artifact, so we shouldn’t run failsafe -->
<activation>
<file>
<!-- can’t rely on ${project.*} for profile activation -->
<missing>${basedir}/src</missing>
</file>
</activation>
<properties>
<skipITs>true</skipITs>
</properties>
</profile>
Full poms
Parent:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- if changed, update spring-boot.version too! -->
<version>2.6.6</version>
<relativePath />
</parent>
<groupId>org.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn verify output:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< org.example:parent >-------------------------
[INFO] Building parent 1.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.2:integration-test (default) # parent ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.619 s
[INFO] Finished at: 2022-04-14T14:07:56+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.22.2:integration-test (default) on project parent: No tests to run! -> [Help 1]
microservice 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">
<parent>
<artifactId>parent</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
<!-- just to be able to build since I can’t actually install the parent -->
<relativePath>../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>microservice</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Build should succeed as long as there are integration tests (and of course all of them are succeeding).
If you want a plugin to not run in the parent, but run in the child, you can add something along the following in the <plugins> section of your parent POM:
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<inherited>false</inherited>
<phase>none</phase>
</execution>
</executions>
</plugin>
This is for the maven source plugin, but you can adapt it for the failsafe plugin as well.

Creating a multi module project with maven spring and kotlin get unresolved reference

I am trying to build a multi module maven project with kotlin and spring. I get an error when the kotlin-maven-plugin runs the compile phase.
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # starter ---
[INFO] Deleting /Users/pnts/IdeaProjects/getyour/base/starter/target
[INFO]
[INFO] --- git-commit-id-plugin:2.2.6:revision (default) # starter ---
[INFO]
[INFO] --- git-commit-id-plugin:2.2.6:revision (get-the-git-infos) # starter ---
[INFO]
[INFO] --- kotlin-maven-plugin:1.3.41:compile (compile) # starter ---
[INFO] Applied plugin: 'spring'
[ERROR] /Users/pnts/IdeaProjects/getyour/base/starter/src/main/kotlin/org/getyour/webdesign/PlainStarter.kt: (6, 9) Unresolved reference: WebsiteEntryPoint
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for parent 0.0.1-SNAPSHOT:
[INFO]
[INFO] parent ............................................. SUCCESS [ 1.178 s]
[INFO] common ............................................. SUCCESS [ 0.021 s]
[INFO] platform-api ....................................... SUCCESS [ 4.238 s]
[INFO] platform-core ...................................... SUCCESS [ 0.215 s]
[INFO] platform-bom ....................................... SUCCESS [ 0.012 s]
[INFO] platform-parent .................................... SUCCESS [ 0.061 s]
[INFO] starter ............................................ FAILURE [ 0.343 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.399 s
[INFO] Finished at: 2019-09-27T08:57:04+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.41:compile (compile) on project starter: Compilation failure
[ERROR] /Users/pnts/IdeaProjects/getyour/base/starter/src/main/kotlin/org/getyour/webdesign/PlainStarter.kt:[6,9] Unresolved reference: WebsiteEntryPoint
[ERROR]
[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 :starter
The funny thing is when I clean my build with "mvn clean" and run the project it compiles and run the spring application.
Spring starts normal
I dont know what causes this issue. Maybe I am missing something.
Here are my poms and my project structure. Hope somebody can help me with this.
parent pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
</parent>
<version>0.0.1-SNAPSHOT</version>
<artifactId>parent</artifactId>
<groupId>org.getyour.webdesign</groupId>
<packaging>pom</packaging>
<modules>
<module>common</module>
<module>starter</module>
</modules>
<!-- properties -->
<properties>
<kotlin.version>1.3.41</kotlin.version>
<spring.boot.version>2.1.8.RELEASE</spring.boot.version>
<java.version>1.8</java.version>
<main.class>org.getyour.webdesign.WebsiteEntryPoint</main.class>
</properties>
<!-- repositories -->
<repositories>
<repository>
<id>maven-central</id>
<url>http://central.maven.org/maven2/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- kotlin spring compiler plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals><goal>compile</goal></goals>
<phase>process-sources</phase>
</execution>
<execution>
<id>test-compile</id>
<goals><goal>test-compile</goal></goals>
<phase>process-test-sources</phase>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.6</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix />
<verbose>false</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<format>properties</format>
<gitDescribe>
<skip>false</skip>
<always>false</always>
<dirty>-dirty</dirty>
</gitDescribe>
</configuration>
</plugin>
</plugins>
</build>
</project>
starter 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>
<parent>
<artifactId>parent</artifactId>
<groupId>org.getyour.webdesign</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<version>0.0.1-SNAPSHOT</version>
<artifactId>starter</artifactId>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.getyour.webdesign</groupId>
<artifactId>platform-bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.getyour.webdesign</groupId>
<artifactId>platform-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
</dependencies>
</project>
WebsiteEntryPoint.kt
package org.getyour.webdesign
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
/**
* Start class of the application
*
* #author p.tsivelekidis
* Created by p.tsivelekidis on 2019-09-20
*/
#SpringBootApplication
class WebsiteEntryPoint {
companion object {
fun main(args: Array<String>) {
runApplication<WebsiteEntryPoint>(*args)
println("Hello!")
}
}
}
PlainStarter.kt
package org.getyour.webdesign
class PlainStarter
fun main(args: Array<String>) {
WebsiteEntryPoint.main(args)
}
Here is my project structure. Notice that when I run the "mvn clean install" command I get this.
project structure after mvn clean install
When I clean my project and just run I get this structure.
project structure after clean and just run project
When I run the mvn clean install it does not create the target classes and I guess for that reason it cant find my WebsiteEntryPoint.
Hope somebody can help me with that. Thanks a lot.
i had the same issue with compiling a kotlin multi module project in intellij.
Command mvn clean install produced the same error with the unresolved dependencies.
As i can see your source directories are named kotlin (as in my project before).
After renaming the source directories in my project to java the problem was solved...

Error with spring-boot-maven-plugin when trying to lauch web app (Spring Vaadin)

hello i'm a beginner in J2EE and web app and i've try to follow a simple get Started from spring (with vaadin for making my UI) https://spring.io/guides/gs/crud-with-vaadin/
When i lauch the command spring-boot:run i got the error below :
[INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) # SampleJPA_Vaadin ---
[WARNING]
java.lang.NoClassDefFoundError: org/springframework/boot/CommandLineRunner
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:492)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.CommandLineRunner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.456 s
[INFO] Finished at: 2018-03-21T20:41:09+01:00
[INFO] Final Memory: 23M/228M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) on project SampleJPA_Vaadin: An exception occurred while running. org/springframework/boot/CommandLineRunner: org.springframework.boot.CommandLineRunner -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
After few research on the net it seams that the CommandLineRunner Class isn't in the jar after the compile process.
But i'm not very comfortable with maven and the process of compiling web app.
So if you can explain me or just give me some link for explanation it would be great, thank you .
Here also 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.metaverse</groupId>
<artifactId>SampleJPA_Vaadin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SampleJPA_Vaadin</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.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>
<vaadin.version>8.3.1</vaadin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
add following to your spring boot maven plugin config
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals><goal>repackage</goal></goals>
<executions>
</plugin>
This will allow you to create a runnable fat jar with all the dependencies. You will get rid of the issue
It doesn't look like you have the spring-boot-starter dependency anywhere, or it's being transitively ignored by your vaadin dependency. You should explicitly include it (referenced by this example online):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
Sorry for silly question, do you have a Class, with public static void main in it :) ?
I just made a Project with your pom, and it needed a Class with main Method to run.
It would help, if you would post your Project on github :)

A required class was missing oracle/jdbc/OracleDriver when executing custom Maven Plugin

I'm trying to build a Maven plugin, that connects & talks to an Oracle XE DB.
My plugin builds without error, but when I try to execute it via Maven, I get at error that OracleDriver is missing.
[INFO] --- script-import-maven-plugin:1.0-SNAPSHOT:import (default-cli) # TOLTAT-SQL-Migration ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.156 s
[INFO] Finished at: 2014-09-19T10:40:25+10:00
[INFO] Final Memory: 4M/490M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT:import (default-cli) on project TOLTAT-SQL-Migration: Execution default-cli of goal com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT:import failed: A required class was missing while executing com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT:import: oracle/jdbc/OracleDriver
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/petertip/.m2/repository/com/tollgroup/tollonline/deploy/script-import-maven-plugin/1.0-SNAPSHOT/script-import-maven-plugin-1.0-SNAPSHOT.jar
[ERROR] urls[1] = file:/C:/Users/petertip/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: oracle.jdbc.OracleDriver
My Maven knowledge is limited, and my Java is fairly rusty.
I am not sure whether I need to put a dependency for ojdbc6 in the plugin's POM. It builds & installs happily without it. Adding it doesn't resolve my problem.
My JAVA is really simple at the moment, just trying to get it to talk to Oracle:
package au.com.toll.toltat.script_import_maven_plugin;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.OracleDriver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
* Goal which imports Stored Procedure scripts
*
* #goal import
*
* #phase process-sources
*/
public class ScriptImportMojo extends AbstractMojo
{
/**
* Location of the file.
* #parameter property="sql.update.directory"
* #required
*/
private String inputUpdateDirectory;
/**
* Location of the file.
* #parameter property="sql.rollback.directory"
* #required
*/
private String inputRollbackDirectory;
public void execute()
throws MojoExecutionException, MojoFailureException
{
try {
// register our JDBC driver
DriverManager.registerDriver (new OracleDriver());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The POM for the plugin is:
<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.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>script-import-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.oracle</groupId> -->
<!-- <artifactId>ojdbc6</artifactId> -->
<!-- <version>11.2.0.2.0</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>
And the POM that's throwing the error is:
<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.tollgroup.tollonline</groupId>
<artifactId>TOLTAT-SQL-Migration</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>script-import-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
<scope>provided</scope>
</dependency -->
<dependency>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<sql.update.directory>update</sql.update.directory>
<sql.rollback.directory>rollback</sql.rollback.directory>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>
Maven does suggest http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException as a possible solution. Unfortunately, that merely indicates that my JAR might be corrupt.
Since the ojdbc6.jar is stored in our Artifactory repository, and no one else is having issues with it, and I have deleted it & re-downloaded it, without any change, I don't think that's my problem.
The ojdbc6 jar exists in my \.m2\repository\com\oracle\ojdbc6\11.2.0.2.0 folder
Is it something as simple (and stupid on my behalf) as that OracleDriver is not in the ojdbc6.jar?
Thanks for any help you can offer,
Peter.
Add the dependency to the plugin config in the POM that is currently failing:
<build>
<plugins>
<plugin>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Fixed it...
I was importing oracle.jdbc.OracleDriver;, when I should have been importing import oracle.jdbc.driver.OracleDriver;.
Both are valid options, but only one is correct. :-(
Also had to change the scope of the ojdbc6 to runtime in the plugin POM.

Grails - building modularized project with maven

I am developing grails 2.3.4 application and I'm trying to add maven (3.1.1) for build purposes. I do it so because my project is modularized (2 plugins, 1 app - for now, there will be many more plugins later) and I would like to have tool that supports it (I failed to use Gradle but thats totally another topic). Recently I found some problems that I don't understand and which makes my brain hurt. I would be very grateful for any help about them.
My project structure looks like this:
my_project/
my_project-domain/ (plugin)
pom.xml
my_project-services/ (plugin)
pom.xml
my_project-webap/ (app)
pom.xml
pom.xml
My parent 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.app.group</groupId>
<artifactId>myArtifactId</artifactId>
<packaging>pom</packaging>
<version>0.0.2</version>
<name>myArtifactId</name>
<properties>
<grails.version>2.3.4</grails.version>
<h2.version>1.3.170</h2.version>
</properties>
<repositories>
...
</repositories>
<modules>
<module>my_project-domain</module>
<module>my_project-services</module>
<module>my_project-webapp</module>
</modules>
<dependencies>
<!-- MONGODB -->
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>mongodb</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
<type>zip</type>
<exclusions>
<!-- proper spring-core and spring-beans version included by org.grails:grails-plugin-services -->
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- TOMCAT needed during testing -->
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.47</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<!-- without h2 TOMCAT throws DataSource errors -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<!-- GRAILS dependencies-->
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-async</artifactId>
<version>${grails.version}</version>
</dependency>
...
</dependencies>
<build>
<pluginManagement/>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
...
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<configuration>
<fork>true</fork>
<!-- for debugging <forkDebug>true</forkDebug> -->
</configuration>
<extensions>true</extensions>
...
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>tools</id>
...
</profile>
</profiles>
</project>
Sample child 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.app.group</groupId>
<artifactId>myArtifactId</artifactId>
<version>0.0.2</version>
<relativePath>..</relativePath>
</parent>
<groupId>my.app.group</groupId>
<artifactId>my_project-services</artifactId>
<packaging>grails-plugin</packaging>
<version>0.0.2</version>
<name>my_project-services</name>
<description>my_project-services</description>
<dependencies>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>rest</artifactId>
<version>0.8</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
</dependencies>
</project>
I can execute integration tests trough:
mvn test - (from parent dir or child dirs) - which executes only unit tests
grails:test-app - (from child dir) - which executes unit and integration tests
mvn grails:test-app - (only from child dir) which executes unit and integration tests - but it executes them two times instead of one (u,i and then once more u,i)
mvn grails:execute -Dcommand=test-app - (only from child dir) - which executes unit and integration tests in the right amount (u,i) BUT during integration tests some of them suddenly start fail(!!!!) It just blows my mind why..
So, if there is anybody who tried to mix grails 2.3, maybe you have some information about:
how can I configure maven to be able to run mvn grails:test-app from parent pom, not to have such result:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] myArtifactId
[INFO] my_project-domain
[INFO] my_project-services
[INFO] my_project-webapp
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myArtifactId 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- grails-maven-plugin:2.3.4:test-app (default-cli) # myArtifactId ---
|Loading Grails 2.3.4
|Configuring classpath
|Running pre-compiled script
.
|Environment set to test
.......
|Application metadata not found, please run: grails upgrade
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] myArtifactId ..................................... FAILURE [7.116s]
[INFO] my_project-domain ................................ SKIPPED
[INFO] my_project-services .............................. SKIPPED
[INFO] my_project-webapp ................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
why integration tests executed by mvn grails:test-app pass and by mvn grails:exec -Dcommand=tests-app fail and how to fix it? I would need exec command for some specific purposes and I want to be able to rely on it. It's my biggest problem, I totally don't understand what could be it's cause
why mvn grails:tests-app results in double tests execution?
why I need to add h2 dependency for tomcat? In my dataSources I have only mongodb configuration and I would like to stick only to it and not see below error every time I execute integration tests:
|Completed 8 unit tests, 0 failed in 0m 2s
........pool.ConnectionPool Unable to create initial connections of pool.
java.sql.SQLException: org.h2.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
...
Caused by: java.lang.ClassNotFoundException: org.h2.Driver
at org.grails.launcher.RootLoader.findClass(RootLoader.java:147)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at org.grails.launcher.RootLoader.loadClass(RootLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:246)
... 331 more
........
|Running 4 integration tests...
Thanks for everybody who got so far and is still reading - no matter if you can help or not:)
Tom

Resources