grails.util.Metadata.getServletVersion throws java.lang.NullPointerException - grails

Calling Holders.grailsApplication.metadata.getServletVersion() throws the following error wherever I place the code:
java.lang.NullPointerException: null
at java.util.Objects.requireNonNull(Objects.java:203)
at java.util.Optional.<init>(Optional.java:96)
at java.util.Optional.of(Optional.java:108)
at grails.util.Metadata.getServletVersion(Metadata.groovy:284)
at grails.util.Metadata$getServletVersion$1.call(Unknown Source)

Add the following to application.yml:
info:
app:
servletVersion: '3.0'
Or set through the command line:
./gradlew bootRun -Dinfo.app.servletVersion=3.0
Having the following in your bootRun block in build.gradle:
bootRun {
systemProperties(System.getProperties())
}

Related

Error initializing classpath: Could not find org.grails.plugins:jasper:1.11.0

I am getting
Error initializing classpath: Could not find org.grails.plugins:jasper:1.11.0.
while I was running grails install-plugin jasper
https://grails.org/plugin/jasper?skipRedirect=true
According to above link I addded
dependencies
{compile "org.grails.plugins:jasper:1.11.0" }
We are not using Maven
So I ran grails install-plugin jasper. I am getting the follwing error
Error Error initializing classpath: Could not find org.grails.plugins:jasper:1.11.0.
Searched in the following locations:
file:/C:/Users/namasivayams/.m2/repository/org/grails/plugins/jasper/1.11.0/jasper-1.11.0.pom
file:/C:/Users/namasivayams/.m2/repository/org/grails/plugins/jasper/1.11.0/jasper-1.11.0.jar
https://repo.grails.org/grails/core/org/grails/plugins/jasper/1.11.0/jasper-1.11.0.jar
I try to download jasper-1.11.0.jar. I could not find any site to download.
How do I fix this error?
Try adding the following repository to build.gradle:
repositories {
maven { url "https://repo.grails.org/grails/plugins" }
// other repositories
}

Failed to apply gradle grails plugin after migrating Grails from 2.x to 3.x

My build.gradle file fails with below error after migrating from Grails 2.x to 3.x.
Failed to apply plugin [id 'grails']
Could not find method create() for arguments [main] on [Java source 'main:j
ava', JVM resources 'main:resources', Java source 'test:java', JVM resources 'te
st:resources'].
The apply plugin: 'grails' is defined within the subprojects task.
Build.gradle
buildscript {
repositories {
mavenLocal()
jcenter()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
classpath 'org.grails:grails-gradle-plugin:2.1.1'
}
}
version = projectVersion
/*
* Subprojects configuration and its tasks
*/
subprojects {
repositories {
mavenLocal()
jcenter()
maven { url "https://repo.grails.org/grails/core" }
}
/*
* Applying Plugins at subproject level
*/
apply plugin: "spring-boot"
apply plugin: 'grails'
apply plugin: "war"
apply plugin: 'eclipse'
apply plugin: 'idea'
Stacktrace
org.gradle.api.GradleScriptException: A problem occurred evaluating root project
'sample'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:93)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$
1.run(DefaultScriptPluginFactory.java:148)
at org.gradle.configuration.ProjectScriptTarget.addConfiguration(Project
ScriptTarget.java:72)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.
apply(DefaultScriptPluginFactory.java:153)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildSc
riptProcessor.java:38)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildSc
riptProcessor.java:25)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.eva
luate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(L
ifecycleProjectEvaluator.java:55)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:491)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:89)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(Task
PathProjectEvaluator.java:42)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuil
dConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLa
uncher.java:126)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:52)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:123)
at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGra
dleLauncher.java:33)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradl
eLauncher.java:100)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradl
eLauncher.java:94)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:62)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:94)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:83)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:94)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(Exe
cuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildA
ctionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:43)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:28)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(Contin
uousBuildActionExecuter.java:77)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(Contin
uousBuildActionExecuter.java:47)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:51)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:28)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:170)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to
apply plugin [id 'grails']
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultP
luginManager.java:160)
at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPlu
ginManager.java:112)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.appl
yType(DefaultObjectConfigurationAction.java:112)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.acce
ss$200(DefaultObjectConfigurationAction.java:35)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.ru
n(DefaultObjectConfigurationAction.java:79)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.exec
ute(DefaultObjectConfigurationAction.java:135)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPlu
ginAware.java:46)
at build_76213vzvbmfxlviw96kj1e2w5$_run_closure2.doCall(C:\build.gradle:73)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedActi
on.java:67)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractPro
ject.java:827)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractPro
ject.java:832)
at org.gradle.api.internal.project.AbstractProject.subprojects(AbstractP
roject.java:815)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMeth
od(BeanDynamicObject.java:232)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObj
ect.java:127)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(Composite
DynamicObject.java:150)
at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:
79)
at build_76213vzvbmfxlviw96kj1e2w5.run(C:\build.gradle:
58)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:91)
... 47 more
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method
create() for arguments [main] on [Java source 'main:java', JVM resources 'main:
resources', Java source 'test:java', JVM resources 'test:resources'].
at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(
AbstractDynamicObject.java:68)
at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDy
namicObject.java:56)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(Composite
DynamicObject.java:175)
at org.gradle.language.base.internal.DefaultProjectSourceSet_Decorated.i
nvokeMethod(Unknown Source)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator$1.execute(Grails
SourceSetConfigurator.groovy:36)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator$1.execute(Grails
SourceSetConfigurator.groovy)
at org.gradle.listener.ActionBroadcast.execute(ActionBroadcast.java:39)
at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDo
mainObjectCollection.java:165)
at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDoma
inObjectCollection.java:159)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.add(Defaul
tNamedDomainObjectCollection.java:81)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(Abs
tractNamedDomainObjectContainer.java:58)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(Abs
tractNamedDomainObjectContainer.java:52)
at org.gradle.api.internal.NamedDomainObjectContainerConfigureDelegate._
configure(NamedDomainObjectContainerConfigureDelegate.java:39)
at org.gradle.api.internal.ConfigureDelegate.invokeMethod(ConfigureDeleg
ate.java:73)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator$_createMainSourc
eSet_closure1.doCall(GrailsSourceSetConfigurator.groovy:59)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedActi
on.java:67)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.configure(
AbstractNamedDomainObjectContainer.java:68)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.configure(
AbstractNamedDomainObjectContainer.java:24)
at org.gradle.api.NamedDomainObjectContainer$configure$0.call(Unknown So
urce)
at org.grails.gradle.plugin.internal.DefaultGrailsProject.sourceSets(Def
aultGrailsProject.groovy:68)
at org.grails.gradle.plugin.GrailsProject$sourceSets.call(Unknown Source
)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator.createMainSource
Set(GrailsSourceSetConfigurator.groovy:58)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator$createMainSource
Set$0.callCurrent(Unknown Source)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator.configure(Grails
SourceSetConfigurator.groovy:50)
at org.grails.gradle.plugin.GrailsSourceSetConfigurator$configure.call(U
nknown Source)
at org.grails.gradle.plugin.GrailsPlugin.configureSourceSets(GrailsPlugi
n.groovy:154)
at org.grails.gradle.plugin.GrailsPlugin$configureSourceSets$0.callCurre
nt(Unknown Source)
at org.grails.gradle.plugin.GrailsPlugin.apply(GrailsPlugin.groovy:105)
at org.grails.gradle.plugin.GrailsPlugin.apply(GrailsPlugin.groovy)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyI
mperative(ImperativeOnlyPluginApplicator.java:35)
at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImpera
tive(RuleBasedPluginApplicator.java:43)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultP
luginManager.java:144)
... 66 more
Try changing (or adding) your Maven repo to:
maven { url "https://repo.grails.org/grails/repo" } (repo instead of core).
The apply plugin: 'grails' does not work with latest grails gradle plugin versions

Grails 3.0.x plugin unable to run integration tests with database

When I run
grails create-app some-app
and
grails create-integration-test SomeTest
with a really complicated test:
expect:
1 == 1
It works just fine. Same when I update the build.gradle
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
/**/compile 'org.postgresql:postgresql:9.4-1201-jdbc41' /**This is new**/
runtime "org.grails.plugins:asset-pipeline"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
}
and the application.yml
dataSource: &pg_baseline ###Only the datasource is updated###
driverClassName: org.postgresql.Driver
dialect: org.hibernate.dialect.PostgreSQLDialect
url: jdbc:postgresql://le-server:5432/LeDatabase
username: ***le superuser***
password: ***le password***
environments:
development:
dataSource:
<< : *pg_baseline
url: le-server:5432/LeDatabase_Dev
test:
dataSource:
<< : *pg_baseline
url: le-server:5432/LeDatabase_Test
to work with a PostgreSQL test database. However, if I follow the same steps but with create-plugin (--profile=plugin, or web-plugin, or not specified profile). Adding the exact same changes to build.gradle + applicatione.yml for the plugin, then running integration tests yields the sweet sweet message:
SomeTest > test something FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.factory.BeanCreationExcepti
on
Caused by: java.lang.NullPointerException
1 test completed, 1 failed
:integrationTest FAILED
In all cases, this is using the following command to run the tests:
grails test-app -integration --stacktrace
Are plugins not able to test against a live database? Do I need some other flag on my test running?

Grails throws ClassNotFoundException when I setup log4j with JDBCAppender

Context
I am trying to setup log4j with JDBCAppender on Grails 2.4.3, I was trying with H2, MySQL and PostgreSQL, but it throws an ClassNotFoundException exception with each driver.
Config.groovy configuration for log4j JDBCAppender:
I have tested user and password credentials information, I mean, I can connect to these databases through Datasource.groovy file.
Test1 with H2:
log4j = {
appenders {
jdbc name: "db",
databaseURL: "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE",
user: "sa",
password: "",
driverClassName: "org.h2.Driver",
sql: "INSERT INTO event_log (log_date, log_message) VALUES ('%d{yyyy.MM.dd HH:mm:ss}', '[%-5p]. Category: %c. Message: %m. User: %X{sessionUserName} DU:[%X{sessionUserDU}]');"
}
root {
info 'grails.app.controller','db'
}
}
Test2 with Postgres:
log4j = {
appenders {
jdbc name: "db",
URL: "jdbc:postgresql://localhost/grailsTestDB",
user: "userDB",
password: "*******",
driver: "org.postgresql.Driver",
layout: pattern(conversionPattern: "[%t] %-5p %c{2} %x - %m%n - %X{username}'"),
sql: "INSERT INTO event_log (accion,nivel,req,logString,usuario) VALUES('%c{2} %x','%-5p','[%t]','%m%n','%X{username}');"
}
root {
info 'grails.app.controller','db'
}
}
Test3 with MySQL:
The next code was taken from an Grails 1.3.8 application, in that application this code works fine.
log4j = {
appenders {
appender new JDBCAppender(
name: "db",
databaseURL: "jdbc:mysql://dbdevsie.db.hostname.com/dbdevsie",
driver: "com.mysql.jdbc.Driver",
user: "dbdevsie231",
password: "********",
layout: pattern(conversionPattern: "[%t] %-5p %c{2} %x - %m%n - %X{username}'"),
sql: "INSERT INTO activity_log (accion,nivel,req,logString,usuario) VALUES('%c{2} %x','%-5p','[%t]','%m%n','%X{username}');"
)
}
root {
info 'grails.app.controller','db'
}
}
Buildconfig.groovy dependencies setup:
dependencies {
runtime 'mysql:mysql-connector-java:5.1.29'
runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
}
Test results:
When I test h2 it throws com.mysql.jdbc.Driver exception.
When I test Mysql it throws sun.jdbc.odbc.JdbcOdbcDriver exception.
When I test Postgresql it throws org.postgresql.Driver exception.
| Error log4j:ERROR Failed to load driver
| Error java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
| Error at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
| Error at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
| Error at java.security.AccessController.doPrivileged(Native Method)
| Error at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
| Error at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
| Error at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
| Error at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
| Error at java.lang.Class.forName0(Native Method)
| Error at java.lang.Class.forName(Class.java:191)
| Error at org.apache.log4j.jdbc.JDBCAppender.setDriver(JDBCAppender.java:391)
| Error at org.apache.log4j.jdbc.JDBCAppender.getConnection(JDBCAppender.java:248)
| Error at org.apache.log4j.jdbc.JDBCAppender.execute(JDBCAppender.java:215)
| Error at org.apache.log4j.jdbc.JDBCAppender.flushBuffer(JDBCAppender.java:289)
| Error at org.apache.log4j.jdbc.JDBCAppender.append(JDBCAppender.java:186)
| Error at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
Additional comments
I also test downloading log4j 1.2.17, PostgreSQL 9.3, and MySQL 5.1.34 jar files and placed them on lib folder, but I have the same result.
Could anyone help me with this thing?
thanks in advance.
Updated
This issue shows in Mac OS, however I ran the same code in linux and there is no problem with it.
OS X Yosemite version 10.10.1
Java 1.7.0_71
You're correct in using the DSL instead of instantiating the appender inline; dependencies and classpath haven't been resolved when your code runs in Config.groovy, so you need some way to delay the actual initialization of the appender until after that happens and the DSL config is a good option.
I got this working, but had different failures than you. In my case both H2 and MySQL reliably crashed my 1.7 JVM early on, but it worked when I switched to 1.8 and now it works in 1.7 also even after deleting pretty much everything. Try getting the dependencies resolved independently by commenting out these config changes, then restarting with them enabled. This might also be due to forking - I almost always disable it by deleting the whole grails.project.fork block in BuildConfig.groovy - if nothing else works, see if that helps.
This is what I had in Config.groovy:
log4j.main = {
appenders {
jdbc name: 'jdbcAppender', driver: 'com.mysql.jdbc.Driver', user: '...',
password: '...', URL: 'jdbc:mysql://localhost/<dbname>',
layout: pattern(conversionPattern:
"insert into logs(log_date, logger, log_level, message) " +
"values('%d{yyyy-MM-dd HH:mm:ss}','%c','%p','%m')")
}
root {
info 'stdout', 'jdbcAppender'
}
error 'org.codehaus.groovy.grails',
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
}
and I created this table to log into:
create table logs (
log_date datetime not null,
log_level varchar(10) not null,
logger varchar(100) not null,
message varchar(1000) not null
) ENGINE=InnoDB;
We utilized a workaround in which we used a dataSource for the jdbc appender
Add a log datasource in Datasource.groovy:
dataSource_log {
url = "jdbc:sqlserver://DBServer:1433;databaseName=Logs;integratedSecurity=true"
dialect = "org.hibernate.dialect.SQLServerDialect"
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
}
Then override where the JDBCAppender gets its connections
public class DataSourceAppender extends JDBCAppender {
SessionFactory sessionFactory;
protected java.sql.Connection getConnection() throws java.sql.SQLException {
SessionImplementor imp = (SessionImplementor) sessionFactory.getCurrentSession();
return imp.getJdbcConnectionAccess().obtainConnection();
}
}
And add this custom appender to log4j in Bootstrap.groovy:
def grailsApplication
def sessionFactory_log
def init = { servletContext ->
def sqlAppender = new DataSourceAppender(
grailsApplication.config.dataSourceAppender
)
sqlAppender.sessionFactory = sessionFactory_log
Logger.getRootLogger().addAppender(sqlAppender)
}
Would love to see a real fix for this though.

How To Fail the 'war' build from within _Events.groovy?

I want to fail the build within my eventListener closure in _Events.groovy under certain circumstances.
I've attempted two approaches:
Throw a RuntimeException()
call ant.fail('failing the build')
I get the following output in the console for both:
| Building WAR file.....
running event listener code...
[ERROR] Invalid environment argument of: 'tingaeuaeou', must be either 'testing', 'package', 'production' or 'native'
| Error Exception occurred trigger event [CreateWarStart]: Sencha SDK optimization failed. (Use --stacktrace to see the full trace)
| Done creating WAR target/product-selector-0.1.war
grails>
Here is my code I've written to attempt to fail the build:
...
ant.exec(outputproperty: "cmdOut", executable: 'sencha',
dir: "$stagingDir", failOnError: true) {
arg(value: 'app')
arg(value: 'build')
arg(value: "-e $senchaEnvironment")
}
def commandOutput = ant.project.properties.cmdOut
println "${commandOutput}"
if(commandOutput.contains('ERROR')){
ant.fail(message:"Sencha SDK optimization failed.",status:1)
}
...
The problem is that the war script keeps on running, generating a war file that will be broken, and I don't think my build process will report an exception happened; my continuous integration build will report a false success!
Any ideas?

Resources