Pass options to the forked JVM - grails

I'm using Grails 2.3.5 and I need to pass an option to the forked JVM. I've tried doing this by setting the JAVA_OPTS environment variable, but that simply gets ignored by the forked JVM. How can I go about passing the forked JVM an option?
I've found this link, which is now dead: http://jira.grails.org/browse/MAVEN-177?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel but that's if you're using the Maven plugin I believe. I'm looking for the equivalent but without having to get Maven plugin involved.

According to: https://grails.github.io/grails2-doc/2.3.0/guide/single.html#forkedMode (near the bottom of the section) you can use jvmArgs in your grails.project.fork configuration. In BuildConfig:
grails.project.fork = [
// ...
run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256, jvmArgs: '..arbitrary JVM arguments..']
// ...
]

Couldn't post a comment. To clarify Andrew's answer, jvmArgs has to be a list.
grails.project.fork = [
// ...
run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256, jvmArgs: ['-Dsome.prop=true', ...] ]
// ...
]

Using Grails 2.5.1 in forked mode running with the Tomcat 7.0.55.3 plugin, I could not get any of the grails.project.fork.jvmArgs solutions to work.
I eventually was able to pass JVM options to the forked process by adding this at the end of my BuildGroovy.config:
grails.tomcat.jvmArgs = ['-jvm_option_here']
See: TomcatServerFactory.groovy

Related

info api not showing git info with gradle-git-properties plugin in grails 4 app

I am trying to get git commit details as part of "/actuator/info" api end point using the gradle-git-properties plugin by following https://guides.grails.org/adding-commit-info/guide/index.html guide but having no luck with it. Steps I followed:
"sdk install grails 4.0.8" //installing latest grails 4 version using sdkman
"sdk use grails 4.0.8" //making sure my current shell is using latest version as well
"grails create-app myapp --profile=rest-api" //creating a dummy app
"cd myapp" //change working dir to the new app
"git init" //initializing git
As per the guide I updated the build.gradle
buildscript {
repositories {
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:7.0.4"
classpath "org.grails.plugins:views-gradle:2.0.2"
classpath "gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:2.2.0"
}
}
version "0.1"
group "myapp"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.plugins.views-json"
apply plugin: "com.gorylenko.gradle-git-properties"
Also updated the application.yml file to enable actuator end points
management:
endpoints:
enabled-by-default: true
run the application using ./gradlew bootRun
I see that the git.properties file is correctly generated and placed under "build/resources/main" folder within the project folder.
But when I hit "http://localhost:8080/actuator/info" in browser, all I see is:
{"app":{"grailsVersion":"4.0.8","version":"0.1","name":"myapp"}}
But no git related info.
Raised the same issue here are well: https://github.com/n0mer/gradle-git-properties/issues/161
Solution has been provided by #virtualdogbert here : https://github.com/n0mer/gradle-git-properties/issues/161#issuecomment-936544990
Basically we have to set path to the git.properties file for dev env:
environments {
development{
spring.info.git.location='file:build/resources/main/git.properties'
}
}

Grails 3 Cookie plugin not found

I want to use the Grails 3 Cookie plugin (http://plugins.grails.org/plugin/ctoestreich/cookie). In my build.gradle I have these entries here:
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
mavenCentral()
}
dependencies {
[...]
compile 'org.grails.plugins:grails-cookie:2.0.5'
[...]
}
But when running gradle build, he's got problems looking up that dependency:
> Could not resolve all dependencies for configuration ':runtime'.
> Could not find org.grails.plugins:grails-cookie:2.0.5.
Searched in the following locations:
file:/home/marp/.m2/repository/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.pom
file:/home/marp/.m2/repository/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.jar
https://repo.grails.org/grails/core/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.pom
https://repo.grails.org/grails/core/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.jar
https://repo1.maven.org/maven2/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.pom
https://repo1.maven.org/maven2/org/grails/plugins/grails-cookie/2.0.5/grails-cookie-2.0.5.jar
Required by:
project :
Do I need to include an other maven repo? Or is the plugin just gone?
Instead compile 'org.grails.plugins:grails-cookie:2.0.5'
use compile 'org.grails.plugins:cookie:2.0.5'
also you can set cookie expiration configuration in application.yml file
Example-grails.plugins.cookie.cookieage.default: 43200
repo of dependency
Hope it helps you
According to this (at the time of writing), 2.0.3 appears to be the newest version on the repo.grails.org repo:
http://repo.grails.org/grails/core/org/grails/plugins/grails-cookie/
change your dependency to:
compile 'org.grails.plugins:cookie:2.0.3'

Add command to Grails build process

I am using the grails-cdn-asset-pipline plugin. I've gone through the installation and configuration steps on GitHub and I reach the usage section which says
Add this command to your build process (usually before war generation and deployment).
// If all the settings are defined in your Config.groovy
grails asset-cdn-push
// Or
grails asset-cdn-push --provider=S3 --directory=my-bucket --gzip=true --storage-path=some-prefix --expires=365 --region=eu-west-1 --access-key=$MY_S3_ACCESS_KEY --secret-key=$MY_S3_SECRET_KEY
Where in my project do I put this command?
Is it something that I can do within the context of my project, or do I need to keep it separate in another build process and run it in an environment like Jenkins?
In _Events.groovy, I tried to invoke the script in the eventCreateWarStart, but I am having no luck there. (Code taken from this question)
eventCreateWarStart = { warName, stagingDir ->
def pluginManager = PluginManagerHolder.pluginManager
def plugin = pluginManager.getGrailsPlugin("cdn-asset-pipline")
def pluginDir = plugin.descriptor.file.parentFile
Map<String, String> env = System.getenv()
final processBuilder = new ProcessBuilder()
processBuilder.directory(new File("${cdnAssetPipelinePluginDir}/scripts"))
processBuilder.command([env['GRAILS_HOME']+"/bin/grails","cdn-asset-push"])
println processBuilder.directory()
Process proc = processBuilder.start()
proc.consumeProcessOutput(out, err)
proc.waitFor()
}
This link explains the run-script functionality which was merged into Grails 1.3.6. But I ran into the same problem of not knowing where to run it automatically.

Publish Karma unit tests in Jenkins

Jenkins already builds my Maven Java project. I want the results of karma unit tests to show up in Jenkins, but unfortunately I cannot introduce any configuration changes in Jenkins. How karma should be configured to acomplish that?
in order for Jenkins to be able to parse karma test results they must be published in the Junit XML format, the plugin that does that is karma-junit-reporter
junit test results (outputFile in the karma configuration file) must be stored in target/surefire-reports/TESTS-TestSuite.xml
reporters : ['progress', 'junit', 'coverage'],
port : 9876,
colors : true,
logLevel : config.LOG_INFO,
// don't watch for file change
autoWatch : false,
// only runs on headless browser
browsers : ['PhantomJS'],
// just run one time
singleRun : true,
// remove `karma-chrome-launcher` because we will be running on PhantomJS
// browser on Jenkins
plugins : [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-junit-reporter',
'karma-coverage',
'karma-jenkins-reporter'
],
// changes type to `cobertura`
coverageReporter : {
type : 'cobertura',
dir : 'target/coverage-reports/'
},
// saves report at `target/surefire-reports/TEST-*.xml` because Jenkins
// looks for this location and file prefix by default.
junitReporter : {
outputDir : 'target/surefire-reports/'
}
Old post, but top result in Google.
Configure karma.conf.js to use 'karma-junit-reporter' and report to outputDir = 'target/karma-reports/'
In your pom.xml, give the test execution step an execution/id like 'karmaTests'
In your pom.xml, set a property jenkins.karmaTest.reportsDirectory = target/karma-reports
Full examples are on this blog post.

Cannot import local plugin in Grails 2.3.11

I cannot import a local plugin inside my app whith these conventions:
grails.plugin.location.MyPlugin= '../MyPlugin'
or
grails.plugin.location.'MyPlugin' = '../MyPlugin'
or
grails.plugin.location.'MyPlugin' = 'c:/prj/MyPlugin'
or
grails.plugin.location.'MyPlugin' = 'c:\\prj\\MyPlugin'
With or without thise inside plugin conf.
//compile ":myplugin:0.1-SNAPSHOT"
The result is :
|Running Grails application
Error |
WARNING: Inline plugins for [MyPlugin] cannot be read due to error: ivy pattern must be absolute:
C:\Users\Luigi\.m2\repository
/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).pom (Use --stacktrace to see the full trace)
Try like this (My home path it's '/home', and the plugin is 'urlrewrite')
grails.project.dependency.resolver = "maven" // or ivy
//use a copy of urlrewrite fixed in enviroment PRODUCCTION because, the repo don't have a functional version for grails 2.5.0
if (Environment.current == Environment.PRODUCTION) {
grails.plugin.location.urlrewrite = '/home/sam/Repositorios/BTask/Programacion/BTask/src/plugins/urlrewrite-0.1'
}
grails.project.dependency.resolution = {
...

Resources