Code coverage don't generate report on azure pipeline - azure-devops

my objective:
is to successfully publish my coverage report in a pipeline on azure devops.
To send it to SonarCloud
my successes
locally on my pc
I manage to generate the coverage report in html format and also in xml
1. script task on my pipeline:
- script: |
npx ng test --code-coverage --karma-config src/karma-ci.conf.js
condition: succeededOrFailed()
displayName: Generate unit tests report
2. kama-ci.config.js file:
module.exports = function (config) {
config.set({
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-junit-reporter'),
require('karma-coverage'),
require('karma-coverage-istanbul-reporter'),
require('#angular-devkit/build-angular/plugins/karma')
],
junitReporter: {
outputDir: 'TestResults/junit',
outputFile: 'unittest-results.xml',
useBrowserName: false
},
coverageReporter: {
type : 'cobertura',
dir : 'TestResults',
subdir: 'coverage',
file: 'code-coverage.xml'
},
reporters: ['progress', 'junit', 'coverage'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--headless',
'--disable-gpu',
'--no-sandbox',
'--remote-debugging-port=9222',
]
}
},
browsers: ['ChromeHeadless'],
singleRun: true
});
};
3. Result error:
But the problem is, report generation always starts and fails in the pipeline.
Here is his result, despite the fact that I give it the condition of always succeeding.
2021-06-02T14:50:42.8314347Z ##[section]Starting: Generate unit tests
2021-06-02T14:50:42.8319061Z ==============================================================================
2021-06-02T14:50:42.8319314Z Task : Command line
2021-06-02T14:50:42.8319582Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2021-06-02T14:50:42.8319857Z Version : 2.182.0
2021-06-02T14:50:42.8320038Z Author : Microsoft Corporation
2021-06-02T14:50:42.8320318Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2021-06-02T14:50:42.8320658Z ==============================================================================
2021-06-02T14:50:42.9528480Z Generating script.
2021-06-02T14:50:42.9529859Z Script contents:
2021-06-02T14:50:42.9530447Z npx ng test --code-coverage --karma-config src/karma-ci.conf.js
2021-06-02T14:50:42.9530922Z ========================== Starting Command Output ===========================
2021-06-02T14:50:42.9558445Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/7177135e-e9ad-4ecf-b6f1-86193e021ca3.sh
2021-06-02T14:51:01.5747869Z [32m02 06 2021 14:51:01.570:INFO [karma-server]: [39mKarma v3.1.4 server started at http://0.0.0.0:9876/
2021-06-02T14:51:01.5749272Z [32m02 06 2021 14:51:01.573:INFO [launcher]: [39mLaunching browsers ChromeHeadless with concurrency unlimited
2021-06-02T14:51:01.5774208Z [32m02 06 2021 14:51:01.577:INFO [launcher]: [39mStarting browser Chrome
2021-06-02T14:51:03.4612458Z
2021-06-02T14:51:03.4614556Z ERROR in [96mapp/services/dealflow-secondary.service.ts[0m:[93m4[0m:[93m37[0m - [91merror[0m[90m TS2307: [0mCannot find module '../entities/ISecondaryPortfolio'.
2021-06-02T14:51:03.4615270Z
2021-06-02T14:51:03.4616058Z [7m4[0m import { ISecondaryPortfolio } from '../entities/ISecondaryPortfolio';
2021-06-02T14:51:03.4616981Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4618161Z [96mapp/shared/api/geography.api.ts[0m:[93m8[0m:[93m27[0m - [91merror[0m[90m TS2307: [0mCannot find module 'src/app/ui/funds/fund-list/models/Geography'.
2021-06-02T14:51:03.4618794Z
2021-06-02T14:51:03.4619553Z [7m8[0m import { Geography } from 'src/app/ui/funds/fund-list/models/Geography';
2021-06-02T14:51:03.4620454Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4621635Z [96mapp/shared/services/geography.service.ts[0m:[93m2[0m:[93m27[0m - [91merror[0m[90m TS2307: [0mCannot find module 'src/app/ui/funds/fund-list/models/Geography'.
2021-06-02T14:51:03.4622232Z
2021-06-02T14:51:03.4622986Z [7m2[0m import { Geography } from 'src/app/ui/funds/fund-list/models/Geography';
2021-06-02T14:51:03.4623886Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4625110Z [96mapp/ui/dealflow/add-fund-portfolio/add-fund-portfolio.component.ts[0m:[93m7[0m:[93m37[0m - [91merror[0m[90m TS2307: [0mCannot find module 'src/app/entities/ISecondaryPortfolio'.
2021-06-02T14:51:03.4625760Z
2021-06-02T14:51:03.4626506Z [7m7[0m import { ISecondaryPortfolio } from 'src/app/entities/ISecondaryPortfolio';
2021-06-02T14:51:03.4627440Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4628643Z [96mapp/ui/dealflow/dealflow.service.ts[0m:[93m13[0m:[93m37[0m - [91merror[0m[90m TS2307: [0mCannot find module '../../entities/ISecondaryPortfolio'.
2021-06-02T14:51:03.4629250Z
2021-06-02T14:51:03.4629996Z [7m13[0m import { ISecondaryPortfolio } from '../../entities/ISecondaryPortfolio';
2021-06-02T14:51:03.4630925Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4632053Z [96mapp/ui/dealflow/models/DealFlow.ts[0m:[93m1[0m:[93m37[0m - [91merror[0m[90m TS2307: [0mCannot find module 'src/app/entities/ISecondaryPortfolio'.
2021-06-02T14:51:03.4632630Z
2021-06-02T14:51:03.4633391Z [7m1[0m import { ISecondaryPortfolio } from "src/app/entities/ISecondaryPortfolio";
2021-06-02T14:51:03.4634782Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4636019Z [96mapp/ui/dealflow/project-secondary/project-secondary.component.ts[0m:[93m15[0m:[93m37[0m - [91merror[0m[90m TS2307: [0mCannot find module '../../../entities/ISecondaryPortfolio'.
2021-06-02T14:51:03.4638214Z
2021-06-02T14:51:03.4640037Z [7m15[0m import { ISecondaryPortfolio } from '../../../entities/ISecondaryPortfolio';
2021-06-02T14:51:03.4641024Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4642193Z [96mapp/ui/dealflow/send-to-mdm-popup/send-to-mdm-popup.component.ts[0m:[93m5[0m:[93m30[0m - [91merror[0m[90m TS2307: [0mCannot find module 'src/app/entities/IMDMResponse'.
2021-06-02T14:51:03.4642778Z
2021-06-02T14:51:03.4643427Z [7m5[0m import { IMDMResponse } from 'src/app/entities/IMDMResponse';
2021-06-02T14:51:03.4644246Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4645318Z [96mapp/ui/dealflow/tests-dealflow/dealflow.spec.ts[0m:[93m1[0m:[93m37[0m - [91merror[0m[90m TS2307: [0mCannot find module '../../../entities/ISecondaryPortfolio'.
2021-06-02T14:51:03.4645885Z
2021-06-02T14:51:03.4646561Z [7m1[0m import { ISecondaryPortfolio } from '../../../entities/ISecondaryPortfolio';
2021-06-02T14:51:03.4647398Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4648510Z [96mapp/ui/funds/fund-list/create-fund/create-fund.component.spec.ts[0m:[93m2[0m:[93m27[0m - [91merror[0m[90m TS2307: [0mCannot find module '../models/Geography'.
2021-06-02T14:51:03.4649050Z
2021-06-02T14:51:03.4649676Z [7m2[0m import { Geography } from '../models/Geography';
2021-06-02T14:51:03.4650403Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4651471Z [96mapp/ui/funds/fund-list/create-fund/create-fund.component.ts[0m:[93m15[0m:[93m27[0m - [91merror[0m[90m TS2307: [0mCannot find module '../models/Geography'.
2021-06-02T14:51:03.4652001Z
2021-06-02T14:51:03.4652603Z [7m15[0m import { Geography } from '../models/Geography';
2021-06-02T14:51:03.4653352Z [7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~[0m
2021-06-02T14:51:03.4653685Z
2021-06-02T14:51:03.5172693Z ##[error]Bash exited with code '1'.
2021-06-02T14:51:03.5208748Z ##[section]Finishing: Generate unit tests

You should add "reporters" inside "coverageReporter" in your karma.config, like so:
coverageReporter: {
type : 'cobertura',
dir : 'TestResults',
subdir: 'coverage',
file: 'code-coverage.xml',
reporters: [ { type: 'cobertura' } ]
},

1. My project is:
Front end project with Node.Js and npm package
Angular CLI: 8.3.23
Node: 12.18.3
OS: win32 x64
Angular: 8.2.14
1. i show you my pipeline
trigger:
tags:
include:
- v*
variables:
- name: ARTIFACTS_FEED_NAME
value: MyFeed
stages:
- stage: Build
jobs:
- job: Build
steps:
- task: NodeTool#0
inputs:
versionSpec: 10.15.x
displayName: Install and use 10.x Node.js version
- task: Npm#1
inputs:
command: install
customRegistry: useFeed
customFeed: $(ARTIFACTS_FEED_NAME)
displayName: Packages restore
- script: |
ls
displayName: Check source output
- script: |
npx ng test --code-coverage --karma-config src/karma-ci.conf.js
condition: succeededOrFailed()
displayName: Generate unit tests report
- script: |
ls src
displayName: Check unit tests output
- task: PublishTestResults#2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/TestResults/junit/unittest-results.xml'
displayName: Publish unit test results
- task: PublishCodeCoverageResults#1
displayName: Publish code coverage report
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
# summaryFileLocation: '$(Build.SourcesDirectory)/coverage/**/TestResults/code-coverage.xml'
summaryFileLocation: '**/src/TestResults/coverage/code-coverage.xml'
failIfCoverageEmpty: true

Related

Eslint behaves differently between local and CI

It seems that eslint behaves different in GitHub actions and in local.
On local I don't get any errors a part from ts warning which are fine.
Wheres in the github actions I seems to get more errors related to some rule about file extension. It's like it doesn't find the files... I am pretty new do GitHub actions but I am not sure what is missing from my config.
CI.yml:
name: Continuous Integration
on:
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Setup Node.js
uses: actions/setup-node#v1
with:
node-version: '15.x'
- uses: actions/checkout#v2
- run: git fetch --prune --unshallow
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache#v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install deps
run: yarn
- name: Lint packages
run: yarn lint
Package.json:
{
"main": "index.js",
"scripts": {
...
"lint": "yarn lint:js && yarn lint:css",
...
},
"dependencies": {
...
},
"devDependencies": {
"#babel/core": "~7.9.0",
"#testing-library/jest-native": "^3.4.3",
"#testing-library/react-native": "^7.1.0",
"#types/jest": "^26.0.20",
"#types/react": "^17.0.1",
"#types/react-native": "^0.63.48",
"#types/react-native-fbsdk": "^3.0.0",
"#types/react-native-maps": "^0.24.0",
"#types/react-native-snap-carousel": "^3.8.2",
"#types/react-native-vector-icons": "^6.4.6",
"#types/react-test-renderer": "^17.0.0",
"#types/styled-components": "^5.1.9",
"#types/styled-components-react-native": "^5.1.1",
"#types/uuid": "^8.3.0",
"#types/yup": "^0.29.11",
"#typescript-eslint/eslint-plugin": "^4.20.0",
"#typescript-eslint/parser": "^4.20.0",
"babel-jest": "~25.2.6",
"babel-plugin-styled-components": "^1.12.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.5",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-react-native": "^3.10.0",
"eslint-plugin-sort-destructure-keys": "^1.3.5",
"husky": "^5.1.3",
"jest": "~25.2.6",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"react-test-renderer": "~16.13.1",
"stylelint": "^13.9.0",
"stylelint-config-standard": "^20.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.10.0",
"typescript": "^4.1.3"
},
"jest": {
"preset": "react-native"
},
"private": true
}
Solution
Rename using git mv <old_filepath> <new_filepath>. You could also first create the new file, copy the content and then delete the old file.
You should do this for all the reported files or directories.
Explanation
I had the same problem until I found out that Git did not save the correct casing of files and directories.
Because Windows and macOS use file systems that are case insensitive, renaming files and directories by just changing the casing, like from Test.js to test.js or from src/Api to src/api, does not change anything for Git.
You can see with git ls-files that there casing did not change from Git's perspective.
When you then go over to GitHub Actions that runs Ubuntu and therefore uses a case sensitive file system, the files can obviously not be found.

(babel plugin) Error: .sourceMap must be a boolean, "inline", "both", or undefined

When attempting to package a nuxt component, I get the above error. I am running nuxt 2.4.5, #babel/core 7.0.0 and rollup 1.4.0.
Does anyone have any thoughts?
Thanks in advance..
npm run script:
"build:es": "rollup --config build/rollup.config.js --format es --file dist/cxl-nuxt-map.esm.js"
Command :
nr build:es
cxl-nuxt-map#1.0.0 build:es /Users/userinfo/Projects/cxl-nuxt-map rollup --config build/rollup.config.js --format es --file dist/cxl-nuxt-map.esm.js
index.js → dist/cxl-nuxt-map.esm.js...
Stack Trace:
[!] (babel plugin) Error: .sourceMap must be a boolean, "inline", "both", or undefined
index.js
Error: .sourceMap must be a boolean, "inline", "both", or undefined
at assertSourceMaps (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/validation/option-assertions.js:65:11)
at Object.keys.forEach.key (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/validation/options.js:107:5)
at Array.forEach (<anonymous>)
at validateNested (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/validation/options.js:83:21)
at validate (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/validation/options.js:74:10)
at file (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/config-chain.js:174:34)
at cachedFunction (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/caching.js:33:19)
at buildRootChain (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/config-chain.js:120:36)
at loadPrivatePartialConfig (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/partial.js:85:55)
at Object.loadPartialConfig (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/#babel/core/lib/config/partial.js:110:18)
at Object.babel.loadPartialConfig (/Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/rollup-plugin-babel/src/index.js:80:20)
at /Users/dan.mahoney/Projects/cxl-nuxt-map/node_modules/rollup/dist/rollup.js:17051:25
at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:804:11)
at internal/main/run_main_module.js:21:11
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cxl-nuxt-map#1.0.0 build:es: `rollup --config build/rollup.config.js --format es --file dist/cxl-nuxt-map.esm.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cxl-nuxt-map#1.0.0 build:es script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dan.mahoney/.npm/_logs/2019-03-01T20_10_17_889Z-debug.log
Rollup.config.js:
/* rollup.config.js */
import vue from 'rollup-plugin-vue';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import replace from 'rollup-plugin-replace';
import { plugin as analyze } from 'rollup-plugin-analyzer';
export default {
input: 'index.js',
output: {
name: 'CxlNuxtMap',
exports: 'named',
},
plugins: [
postcss({
extensions: ['.css'],
runtimeHelpers: true,
exclude: 'node_modules/**',
}),
vue(),
babel({
exclude: 'node_modules/**',
}),
replace({
'process.env.INCLUDE_DEPS': JSON.stringify('false'),
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
commonjs({
namedExports: {},
}),
analyze({ stdout: true }),
],
};
Found in the problem in my .babelrc file. The offending line was:
"sourceMap": "true",
should be:
"sourceMaps": true,

Webdriver keep on executing the scenarios without terminating the job

I used the below protractor cucumber multiCapabilities config file to execute my scenarios. While executing the config file, First time Chrome and Firefox got launched and my expected scenario got executed. But after the execution the job not got finished. The webdriver keep on launching the browsers and ending with 0 scenarios / 0 steps / 0m00.000s results. Can anyone help me to handle this situation.
Config file:
exports.config = {
seleniumAddress: "http://localhost:4444/wd/hub",
baseUrl: "https://www.google.co.in/",
multiCapabilities: [
{
browserName: "chrome",
shardTestFiles: true,
maxInstances: 1
},
{
browserName: "firefox",
shardTestFiles: true,
maxInstances: 1
}
],
framework: "custom",
frameworkPath: require.resolve("protractor-cucumber-framework"),
specs: ["../features/*.feature"],
cucumberOpts: {
format: 'json:results.json',
require: ["../stepDefinitions/*.js"],
tags: ['#sample']
}
};
Output:
I/launcher - 2 instance(s) of WebDriver still running
I/testLogger -
------------------------------------
I/testLogger - [chrome #01-0] PID: XXXXX
#Expected scenario got executed
I/launcher - 2 instance(s) of WebDriver still running
I/testLogger -
------------------------------------
I/testLogger - [firefox #11-0] PID: XXXXX
#Expected scenario got executed
I/launcher - 2 instance(s) of WebDriver still running
I/testLogger -
------------------------------------
I/testLogger - [firefox #11-1] PID: XXXXX
[firefox #11-1] 0 scenarios
[firefox #11-1] 0 steps
[firefox #11-1] 0m00.000s
I/launcher - 2 instance(s) of WebDriver still running
I/testLogger -
------------------------------------
I/testLogger - [chrome #01-1] PID: XXXXX
[chrome #01-1] 0 scenarios
[chrome #01-1] 0 steps
[chrome #01-1] 0m00.000s
And the webdriver keep on execution the scenarios until I manually terminate the job.

could not find cucumber plugin for protractor test

i am brand new to protractor and did setup as per the instructions from the protractor website. When i try to run the protractor test with the a cucumber framework i always get "Error: Error: Cannot find module 'cucumber'". Any help on this? below are by configurations.
cucumber-conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
browserName:'chrome'
},
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'./cucumber/*.feature'
],
cucumberOpts: {
require: ['./cucumber/*.js'],
tags: [],
strict: true,
format: ["pretty"],
dryRun: false,
compiler: []
},
onPrepare: function () {
browser.manage().window().maximize();
}
};
when i run protractor cucumber-conf.js i get below error.
/opt/protractor_tests
➔ protractor cucumber-conf.js
(node:5681) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[12:06:55] I/launcher - Running 1 instances of WebDriver
[12:06:55] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[12:06:57] E/launcher - Error: Error: Cannot find module 'cucumber'
at Function.Module._resolveFilename (module.js:472:15)
at Function.Module._load (module.js:420:25)
at Module.require (module.js:500:17)
at require (internal/module.js:20:19)
at Object.module.exports.load (/opt/protractor_tests/node_modules/protractor-cucumber-framework/lib/cucumberLoader.js:5:12)
at Object.<anonymous> (/opt/protractor_tests/node_modules/protractor-cucumber-framework/index.js:5:48)
at Module._compile (module.js:573:32)
at Object.Module._extensions..js (module.js:582:10)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
[12:06:57] E/launcher - Process exited with error code 100

Installing and using MongoDB in Grails 3.x

I've been following Manning's Grails In Action, but their section on configuring data sources is woefully out-of-date for Grails 3.0.3.
My intention is to convert from the default data source of H2 to MongoDB version 3.0.2. Google searches have yielded conflicting results -- many answers are often for earlier versions of Grails, which used 'BuildConfig.groovy' and 'DataSources.groovy' in order to establish plug-ins and data sources.
I've downloaded the 3.0.2 JDBC for MongoDB and stored it in various folders (i.e. the root of the application, a created /lib/ folder, and in /grails-app/conf/) without success.
My application.yml file reads:
---
grails:
profile: web
codegen:
defaultPackage: qotd
info:
app:
name: '#info.app.name#'
version: '#info.app.version#'
grailsVersion: '#info.app.grailsVersion#'
spring:
groovy:
template:
check-template-location: false
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlets: html
taglib: none
staticparts: none
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
dataSource:
pooled: true
jmxExport: true
host: 'localhost'
port: 27017
driverClassName: mongodb-driver-3.0.2.jar
databaseName: 'test_db'
environments:
development:
dataSource:
dbCreate: create
url: jdbc:mongodb://localhost:27017
test:
dataSource:
dbCreate: update
url: jdbc:mongodb://localhost:27017
production:
dataSource:
dbCreate: update
url: jdbc:mongodb://localhost:27017
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
My build.gradle file reads:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.1.1'
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
}
version "0.1"
group "qotd"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
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.mongodb:mongodb-driver:3.0.2'
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
runtime "org.grails.plugins:asset-pipeline"
runtime "org.grails.plugins:scaffolding"
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"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
... and finally, the actual stack trace when I try to execute $ grails run-app is:
java.util.concurrent.ExecutionException: org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
at java_util_concurrent_Future$get.call(Unknown Source)
at run-app.run(run-app.groovy:90)
at org.grails.cli.profile.commands.script.GroovyScriptCommand.handle(GroovyScriptCommand.groovy:152)
at org.grails.cli.profile.DefaultProfile.handleCommand(DefaultProfile.groovy:177)
at org.grails.cli.GrailsCli.handleCommand(GrailsCli.groovy:239)
at org.grails.cli.GrailsCli.handleCommand(GrailsCli.groovy:220)
at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:198)
at org.grails.cli.GrailsCli.main(GrailsCli.groovy:99)
Caused by: org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:57)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
at org.gradle.tooling.internal.consumer.DefaultBuildLauncher.run(DefaultBuildLauncher.java:71)
at org.grails.cli.gradle.GradleUtil$_runBuildWithConsoleOutput_closure4.doCall(GradleUtil.groovy:109)
at org.grails.cli.gradle.GradleUtil$_withProjectConnection_closure2.doCall(GradleUtil.groovy:89)
at org.grails.cli.gradle.GradleUtil$_withProjectConnection_closure2.call(GradleUtil.groovy)
at grails.io.support.SystemOutErrCapturer.withNullOutput(SystemOutErrCapturer.groovy:64)
at org.grails.cli.gradle.GradleUtil.withProjectConnection(GradleUtil.groovy:88)
at org.grails.cli.gradle.GradleUtil.runBuildWithConsoleOutput(GradleUtil.groovy:104)
at org.grails.cli.gradle.GradleInvoker.invokeMethod(GradleInvoker.groovy:50)
at org.grails.cli.gradle.GradleAsyncInvoker$_invokeMethod_closure2.doCall(GradleAsyncInvoker.groovy:51)
at org.grails.cli.gradle.GradleAsyncInvoker$_invokeMethod_closure2.doCall(GradleAsyncInvoker.groovy)
Caused by: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':bootRun'.
at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:77)
at org.gradle.initialization.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
at org.gradle.initialization.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:30)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:108)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:43)
at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30)
at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:119)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:48)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:71)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':bootRun'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:306)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
... 34 more
Caused by: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85.x86_64/jre/bin/java'' finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:31)
at org.gradle.api.tasks.JavaExec.exec(JavaExec.java:60)
at org.springframework.boot.gradle.run.BootRunTask.exec(BootRunTask.java:58)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 57 more
| Error Failed to start server
Any help would be greatly appreciated; many hours have been spent slamming my head against my desk and finding unhelpful search results.
Yeah, it's a challenge finding up-to-date documentation for configuring Grails 3.0 to use MongoDB. The solution below was cobbled together from various sources.
build.gradle
dependencies {
...
compile "org.grails.plugins:mongodb"
...
}
You do not need to manually download and install any JDBC files.
grails-app/conf/application.yml
environments:
development:
grails:
mongodb:
connectionString: "mongodb://localhost:27017/project-db"
grails-app/domain/com/example/Book.groovy
package com.example
import org.bson.types.ObjectId
class Book {
ObjectId id
String title
static mapWith = "mongo"
}
I've been successfully using this approach since Grails 3.0.1, and it's still working with 3.0.4.
Dem Pilafian is great and correct. Mine is just slightly different. You can leave out the mapping in your classes and rely on mongodb to directly store your objects. All you need to do is remove hibernate from your project.
Using Grails 3.1.7
build.gradle
dependencies {
compile "org.grails.plugins:mongodb"
//compile "org.grails.plugins:hibernate4"
//compile "org.hibernate:hibernate-ehcache"
//runtime "com.h2database:h2"
}
I've commented out the hibernate and h2 dependencies. You can delete them entirely of course, if you use only mongodb.
grails-app/conf/application.yml
environments:
development:
grails:
mongodb:
host: "hostname"
port: 27017
databaseName: development
In the application.yml you need to remove the hibernate: section and the driverClassName: org.h2.Driver.
For more background information as well as additional configuration options, refer to: GORM Grails MongoDB
This way, you will bypass hibernate completely and don't need to define a mapping in your classes. Your objects will be directly stored as structured documents in mongo.