Grails Fixtures: grails run-app works, but mvn grails:run-app not - maven

I have installed the Grails Fixtures plugin (http://www.grails.org/plugin/fixtures) for loading some initial datas into my database for dev and test environment. I also use Grails with Maven integration.
I have added my data loading code into the BootStrap.groovy:
import grails.util.Environment
class BootStrap {
def fixtureLoader
def init = { servletContext ->
if (Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST) {
//def fixtureLoader = new FixtureLoader(grailsApplication)
fixtureLoader.load("init")
}
}
}
When I run my Grails app with "grail run-app" it works perfectly, but if I use the Maven Grails command "mvn grails:run-app -Dgrails.env=development" then it doesn't work. It throws following error:
Error executing bootstraps; nested exception is java.lang.NullPointerException: Cannot invoke method load() on null object
It seems that the "fixtureLoader" bean is not correctly initialized if I use the Maven Grails command "mvn grails:run-app".
Do you have any idea? Or maybe its a bug...

Add it as a dependency in pom.xml instead of BuildConfig.groovy. Maven looks at the pom to resolve dependencies (in this case a plugin).
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>fixtures</artifactId>
<version>1.0.7</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
Note: scope runtime makes the artifact available in test scope as well.

Related

Maven runs JUnit 5 tests but does not run TestFactory method

I have a number of tests in a project which I am able to run using Maven (mvn test), all of these are JUnit 5 using the org.junit.jupiter.api.Test annotation.
I have one other class which has a method using the org.junit.jupiter.api.TestFactory annotation. When I run the tests in IDEA all the tests run and the TestFactory is run as expected (it is used as a factory to generate a number of tests, each of which runs and then the results are produced).
When I run in Maven it says it is running the class but it doesn't run any methods within it and the test factory method code isn't run.
Here's some example code showing the import and how it is being used on the method.
import org.junit.jupiter.api.TestFactory;
...class definition here etc...
#TestFactory
public Collection<DynamicTest> runTests() throws Exception {
System.out.println("[Test] TestFactory test running");
... other code here...
}
Maven will say it is running the class but the printout above will not occur.
I've tried adding another empty test method which uses the #Test annotation but this also doesn't run.
If I have maven specifically run this test using -Dtest=xxx Maven will even print out that it is running the test but then show that no tests have been run:
Running tests.FactoryTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Update: changing the name of a method to start with 'test' means that Maven does run the method, and if I change that method to start with something else (e.g. 'run') maven does not run it. This is also a difference between IDEA and Maven it seems (IDEA will run whatever is marked as a #Test but Maven seems to require some sort of naming convention). But that said, altering the name of the #TestFactory method still doesn't get Maven to run it.
Is there a simple way to get maven to handle the depencies etc when running the tests but just use the same mechanism as IDEA or just use a more standard JUnit way to run the tests rather than applying its own interpretations?
Pom file as it relates to JUnit:
<properties>
<junit-platform.version>5.9.1</junit-platform.version>
</properties>
...
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<type>maven-plugin</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
mvn -v output:
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/local/Cellar/maven/3.8.5/libexec
Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
You have not configured Maven Surefire correctly.
Thus, I assume that your tests are "running" using POJO Tests.
See the official JUnit 5 - Maven sample application for a working example with JUnit Jupiter and Maven Surefire.

getting java.lang.NoClassDefFoundError: org/testng/IInvokedMethodListener2 error for testng maven project in intellij

I have tried adding the TestNG jar files to the project folder removing the testNG dependencies and adding them again
but the issue is not resolved still showing the same error
if you are using the Gradle plugin and are still having this issue, change allureJavaVersion in build.gradle to version or higher:
allure {
version = '2.13.2'
autoconfigure = true
aspectjweaver = true
allureJavaVersion = '2.13.2'
}
if you are using maven update allure with version 2.13.2 or higher
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.13.2</version>
</dependency>
Ref: https://github.com/allure-framework/allure-java/pull/422

Add plugin dependency in grails

I am trying to add dependency of a plugin into my grails application, but it doesnot have any plugins in grails repo. It can be added to maven project as :
<dependency>
<groupId>com.plaid</groupId>
<artifactId>plaid-java</artifactId>
<version>0.2.12</version>
</dependency>
As my project is also maven based. How do i add this plugin into my project.
P.S. : IT cannot be added in plugins and dependencies since there is no grails plugin associated with that.
Any help is appreciated.
You can use the create-pom org.mycompany to create your pom.xml file to make grails read the pom.xml you need to set in BuildConfig.groovy this code
grails.project.dependency.resolution = {
/*YOUR CONFIG*/
pom true
repositories {
/*YOUR RESPOSITORIES*/
}
}
Then you need to add your dependency in this pom.xml
You can see the official doc. in this link
We can add dependency for any plugin in grails under dependencies{} in BuildConfig.groovy as:
<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
For your case, the equivalent for:
<dependency>
<groupId>com.plaid</groupId>
<artifactId>plaid-java</artifactId>
<version>0.2.12</version>
</dependency>
is:
dependencies{
compile "com.plaid:plaid-java:0.2.12"
}
For more you can have a look into http://docs.grails.org/2.3.1/guide/conf.html

Error: ClassCastException occured while adding dependency jar in pom.xml

Can any one suggest how to resolve the ClassCastException while adding dependency jar in pom.xml?
I have created a new maven project having returning the object in runtime and then execute the ovverride method definition as based upon client request.
Ex: actionPerform(actionType) -- this method return the 'Object'
public static CommonActions action(ActionTypes actionType)
{
return (CommonActions)actionPerform(actionType);
}
Code is working fine and then successfully executing. There is no ClassCastExceptions while adding this jar into library tab on project properties using eclipse.
Getting ClassCastExceptions on above return statement while adding the below depenedency in pom.xml
<dependency>
<groupId>com.amadeus.selenium.merci</groupId>
<artifactId>appium-amadeus-utilities</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
I am using maven version 3.0.4
Please suggest how I resolve the ClassCastException at runtime while adding dependency jar in pom.xml.

NoClassDefFoundError with jetty-maven-plugin

I am getting a:
he Cause java.lang.NoClassDefFoundError Msg:net/spy/memcached/MemcachedClient
When executing jetty:run -e in eclipse. Why isn't this dependency being added into the classpath?
Which classpath do you expect it to be added to? If something in your project is trying to load it, ensure you have a project dependency that has that class in it. It looks like it comes from ServiceMix. If you've added something to Jetty itself to make it require that class, then add the dependency to the jetty plugin.
Your code is missing a runtime dependency. I searched Maven Central for the missing class
http://search.maven.org/#search|ga|1|fc%3A%22net.spy.memcached.MemcachedClient%22
Try adding the following to your POM:
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spymemcached</artifactId>
<version>2.5_2</version>
<packaging>bundle</packaging>
</dependency>
The dependency had a provided scope. Change this.

Resources