I want to include a folder and its contents in the test resources for a Gradle project.
Let's say I have the following project structure:
projectRoot
| - src
| | - main
| | \ - java
| \ - test
| \ - java
\ - vars
\ - *.groovy files
The vars folder contains several *.groovy files that I want to be included in the test resources when the project is built. However, the test resources must include the vars folder, not just the contents inside that folder.
If I add the following block to my buid.gradle file, it only puts the contents of that folder in the test resources:
sourceSets {
test {
resources {
srcDir "vars"
}
}
}
This makes the build/resources/test directory contain the contents of the vars folder, but not the vars folder itself:
projectRoot
| - build
| \ - resources
| \ - test
| \ - *.groovy files
| - src
| | - main
| | \ - java
| \ - test
| \ - java
\ - vars
\ - *.groovy files
However, what I really am after is this:
projectRoot
| - build
| \ - resources
| \ - test
| \ - vars
| \ - *.groovy files
| - src
| | - main
| | \ - java
| \ - test
| \ - java
\ - vars
\ - *.groovy files
(Notice how the vars folder is listed in the build/resources/test folder)
How do I do this?
Note: I cannot make changes to the directory structure of the project (i.e. the vars folder cannot have any sub-directories, and it must be top level).
Perhaps something like this will work:
task copyConfig(type: Copy) {
from "${project.projectDir}/vars/*.*"
into "${project.projectDir}/.build/resources/test/vars"
dependsOn processTestResources
}
copyConfig.mustRunAfter(processTestResources)
testClasses.dependsOn copyConfig
testClasses.mustRunAfter copyConfig
Related
The problem is simple: liquibase fails to find my changeset sqlfile to run it against my db.
Paths are as follows:
SqlCl: C:\Oracle\sqlcl
No CLASSPATH is defined in user env variables
Main changelog file: C:\repos\odb\db-scripts\main.yaml
Changeset sqlfile: C:\repos\odb\db-scripts\test.sql
main.yaml contains:
databaseChangeLog:
- changeSet:
id: 1
author: some_author
changes:
- sqlFile:
path: test.sql
splitStatements: true
endDelimiter: /
stripComments: true
test.sql contains:
create or replace view asdas
as
select 1 val from dual
/
What I get when I run liquibase update via sqlcl:
C:\repos\odb\db-scripts>sql stat_adm#dev-odb1
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
SQLcl: Release 20.4 Production on Tue May 25 18:03:50 2021
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Password? (**********?) ********
Last Successful login time: Tue May 25 2021 18:03:55 +03:00
Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.7.0.0.0
SQL> lb update -changelog main.yaml
Processing has failed for your request.
liquibase.exception.UnexpectedLiquibaseException: java.io.IOException: The file test.sql was not found in
- C:\Oracle\jdbc\lib\ojdbc8.jar
- C:\Oracle\jlib\orai18n-mapping.jar
- C:\Oracle\jlib\orai18n-utility.jar
- C:\Oracle\jlib\orai18n.jar
- C:\Oracle\lib\ojdbc8.jar
- C:\Oracle\modules\oracle.xdk\xmlparserv2.jar
- C:\Oracle\rdbms\jlib\xdb6.jar
- C:\Oracle\sqlcl\lib
- C:\Oracle\sqlcl\lib\ST4.jar
- C:\Oracle\sqlcl\lib\antlr-runtime.jar
- C:\Oracle\sqlcl\lib\commons-codec.jar
- C:\Oracle\sqlcl\lib\commons-logging.jar
- C:\Oracle\sqlcl\lib\dbtools-common.jar
- C:\Oracle\sqlcl\lib\dbtools-data.jar
- C:\Oracle\sqlcl\lib\dbtools-http.jar
- C:\Oracle\sqlcl\lib\dbtools-net.jar
- C:\Oracle\sqlcl\lib\dbtools-sqlcl.jar
- C:\Oracle\sqlcl\lib\ext
- C:\Oracle\sqlcl\lib\ext\dbtools-liquibase.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-cli-ext.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-common.jar
- C:\Oracle\sqlcl\lib\ext\liquibase-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-postgres.jar
- C:\Oracle\sqlcl\lib\ext\snakeyaml-1.12.jar
- C:\Oracle\sqlcl\lib\guava.jar
- C:\Oracle\sqlcl\lib\httpclient.jar
- C:\Oracle\sqlcl\lib\httpcore.jar
- C:\Oracle\sqlcl\lib\httpmime.jar
- C:\Oracle\sqlcl\lib\jackson-annotations.jar
- C:\Oracle\sqlcl\lib\jackson-core.jar
- C:\Oracle\sqlcl\lib\jackson-jr-objects.jar
- C:\Oracle\sqlcl\lib\jackson-jr-stree.jar
- C:\Oracle\sqlcl\lib\jansi.jar
- C:\Oracle\sqlcl\lib\javax.json.jar
- C:\Oracle\sqlcl\lib\jdbcrest.jar
- C:\Oracle\sqlcl\lib\jline.jar
- C:\Oracle\sqlcl\lib\ojdbc8.jar
- C:\Oracle\sqlcl\lib\oraclepki.jar
- C:\Oracle\sqlcl\lib\orai18n-collation.jar
- C:\Oracle\sqlcl\lib\orai18n-mapping.jar
- C:\Oracle\sqlcl\lib\orai18n-servlet.jar
- C:\Oracle\sqlcl\lib\orai18n-utility.jar
- C:\Oracle\sqlcl\lib\orai18n.jar
- C:\Oracle\sqlcl\lib\orajsoda.jar
- C:\Oracle\sqlcl\lib\osdt_cert.jar
- C:\Oracle\sqlcl\lib\osdt_core.jar
- C:\Oracle\sqlcl\lib\slf4j-api.jar
- C:\Oracle\sqlcl\lib\slf4j-jdk14.jar
- C:\Oracle\sqlcl\lib\sshd-common.jar
- C:\Oracle\sqlcl\lib\sshd-contrib.jar
- C:\Oracle\sqlcl\lib\sshd-core.jar
- C:\Oracle\sqlcl\lib\xdb6.jar
- C:\Oracle\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar
- C:\Oracle\sqlcl\lib\xmlparserv2.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\access-bridge-64.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\cldrdata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\dnsns.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jaccess.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jfxrt.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\localedata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\nashorn.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunec.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunjce_provider.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunmscapi.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunpkcs11.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\zipfs.jar
- C:\jdbc\lib\ojdbc8.jar
- C:\jlib\orai18n-mapping.jar
- C:\jlib\orai18n-utility.jar
- C:\jlib\orai18n.jar
- C:\rdbms\jlib\xdb6.jar
- C:\repos\odb\db-scripts\ST4-4.3.1.jar
- C:\repos\odb\db-scripts\antlr-runtime-3.5.2.jar
- C:\repos\odb\db-scripts\commons-codec-1.15.jar
- C:\repos\odb\db-scripts\commons-logging-1.2.0.0.1.jar
- C:\repos\odb\db-scripts\dbtools-common-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-data-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-http-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-net-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-sqlcl-20.4.1.jar
- C:\repos\odb\db-scripts\guava-30.0-jre.jar
- C:\repos\odb\db-scripts\httpclient-4.5.13.jar
- C:\repos\odb\db-scripts\httpcore-4.4.13.jar
- C:\repos\odb\db-scripts\httpmime-4.5.13.jar
- C:\repos\odb\db-scripts\jackson-annotations-2.11.3.jar
- C:\repos\odb\db-scripts\jackson-core-2.11.3.jar
- C:\repos\odb\db-scripts\jackson-jr-objects-2.11.3.jar
- C:\repos\odb\db-scripts\jackson-jr-stree-2.11.3.jar
- C:\repos\odb\db-scripts\jansi-1.18.jar
- C:\repos\odb\db-scripts\javax.activation-api-1.2.0.jar
- C:\repos\odb\db-scripts\javax.json-1.1.4.jar
- C:\repos\odb\db-scripts\jaxb-api-2.4.0-b180830.0359.jar
- C:\repos\odb\db-scripts\jdbcrest-20.4.1.jar
- C:\repos\odb\db-scripts\jline-2.14.6.jar
- C:\repos\odb\db-scripts\low-level-api-13.0.0.jar
- C:\repos\odb\db-scripts\ojdbc8-21.0.0.jar
- C:\repos\odb\db-scripts\oraclepki-21.0.0.jar
- C:\repos\odb\db-scripts\orai18n-21.0.0.jar
- C:\repos\odb\db-scripts\orai18n-mapping-21.0.0.jar
- C:\repos\odb\db-scripts\orai18n-utility-21.0.0.jar
- C:\repos\odb\db-scripts\orajsoda-1.1.3.jar
- C:\repos\odb\db-scripts\osdt_cert-21.0.0.jar
- C:\repos\odb\db-scripts\osdt_core-21.0.0.jar
- C:\repos\odb\db-scripts\slf4j-api-1.7.30.jar
- C:\repos\odb\db-scripts\slf4j-jdk14-1.7.30.jar
- C:\repos\odb\db-scripts\sshd-common-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-contrib-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-core-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-scp-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-sftp-2.5.0.jar
- C:\repos\odb\db-scripts\ucp-21.0.0.jar
- C:\repos\odb\db-scripts\xdb6-21.0.0.jar
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
SQL>
Somehow it picks up C:\repos\odb\db-scripts\ path but there are just imaginary jar that don't persist there. By the way paths C:\jdbc\lib\, C:\jlib\, C:\rdbms\jlib\xdb6.jar don't even exist on my machine.
Adding relativeToChangelogFile: true to main.yaml doesn't help.
How should I tell sqlcl to pick up test.sql file from the current directory or at least provide a full path?
EDIT:
I decided to run it using liquibase itself. I downloaded liquibase installation zip archive and took liquibase.bat from it and put it into sqlcl installation path. Then I added this path to my PATH variable so that I can call it from command line.
Also I created in C:\repos\odb\db-scripts\ file liquibase.properties with the following contents:
changeLogFile: main.yaml
driver: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:#mega-db-host:1521/odb1
username: usr
password: pwd
Note that C:\repos\odb\db-scripts\ is the same dir for test.sql and main.yaml. After that I've run liquibase:
C:\repos\odb\db-scripts>liquibase update
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
####################################################
## _ _ _ _ ##
## | | (_) (_) | ##
## | | _ __ _ _ _ _| |__ __ _ ___ ___ ##
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ##
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ##
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ##
## | | ##
## |_| ##
## ##
## Get documentation at docs.liquibase.com ##
## Get certified courses at learn.liquibase.com ##
## Get advanced features and support at ##
## liquibase.com/support ##
## ##
####################################################
Starting Liquibase at 10:11:50 (version 4.1.1 #0 built at 2020-11-02 16:02+0000)
ScriptRunner Executing: create or replace view asdas
as
select 1 val from dualLiquibase Executed:create or replace view asdas
as
select 1 val from dual
Liquibase: Update has been successful.
See: no errors. After that I decided to set non-existing path to sql file and guess what I've got:
C:\repos\odb\db-scripts>liquibase update
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
####################################################
## _ _ _ _ ##
## | | (_) (_) | ##
## | | _ __ _ _ _ _| |__ __ _ ___ ___ ##
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ##
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ##
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ##
## | | ##
## |_| ##
## ##
## Get documentation at docs.liquibase.com ##
## Get certified courses at learn.liquibase.com ##
## Get advanced features and support at ##
## liquibase.com/support ##
## ##
####################################################
Starting Liquibase at 10:12:44 (version 4.1.1 #0 built at 2020-11-02 16:02+0000)
Unexpected error running Liquibase: java.io.IOException: The file not_exists.sql was not found in
- C:\Oracle\sqlcl\lib
- C:\Oracle\sqlcl\lib\ST4.jar
- C:\Oracle\sqlcl\lib\antlr-runtime.jar
- C:\Oracle\sqlcl\lib\commons-codec.jar
- C:\Oracle\sqlcl\lib\commons-logging.jar
- C:\Oracle\sqlcl\lib\dbtools-common.jar
- C:\Oracle\sqlcl\lib\dbtools-data.jar
- C:\Oracle\sqlcl\lib\dbtools-http.jar
- C:\Oracle\sqlcl\lib\dbtools-net.jar
- C:\Oracle\sqlcl\lib\dbtools-sqlcl.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-liquibase.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-cli-ext.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-common.jar
- C:\Oracle\sqlcl\lib\ext\liquibase-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-postgres.jar
- C:\Oracle\sqlcl\lib\ext\snakeyaml-1.12.jar
- C:\Oracle\sqlcl\lib\guava.jar
- C:\Oracle\sqlcl\lib\httpclient.jar
- C:\Oracle\sqlcl\lib\httpcore.jar
- C:\Oracle\sqlcl\lib\httpmime.jar
- C:\Oracle\sqlcl\lib\jackson-annotations.jar
- C:\Oracle\sqlcl\lib\jackson-core.jar
- C:\Oracle\sqlcl\lib\jackson-jr-objects.jar
- C:\Oracle\sqlcl\lib\jackson-jr-stree.jar
- C:\Oracle\sqlcl\lib\jansi.jar
- C:\Oracle\sqlcl\lib\javax.activation-api.jar
- C:\Oracle\sqlcl\lib\javax.json.jar
- C:\Oracle\sqlcl\lib\jaxb-api.jar
- C:\Oracle\sqlcl\lib\jdbcrest.jar
- C:\Oracle\sqlcl\lib\jline.jar
- C:\Oracle\sqlcl\lib\low-level-api.jar
- C:\Oracle\sqlcl\lib\ojdbc8.jar
- C:\Oracle\sqlcl\lib\oraclepki.jar
- C:\Oracle\sqlcl\lib\orai18n-mapping.jar
- C:\Oracle\sqlcl\lib\orai18n-utility.jar
- C:\Oracle\sqlcl\lib\orai18n.jar
- C:\Oracle\sqlcl\lib\orajsoda.jar
- C:\Oracle\sqlcl\lib\osdt_cert.jar
- C:\Oracle\sqlcl\lib\osdt_core.jar
- C:\Oracle\sqlcl\lib\slf4j-api.jar
- C:\Oracle\sqlcl\lib\slf4j-jdk14.jar
- C:\Oracle\sqlcl\lib\snakeyaml-1.12.jar
- C:\Oracle\sqlcl\lib\sshd-common.jar
- C:\Oracle\sqlcl\lib\sshd-contrib.jar
- C:\Oracle\sqlcl\lib\sshd-core.jar
- C:\Oracle\sqlcl\lib\sshd-scp.jar
- C:\Oracle\sqlcl\lib\sshd-sftp.jar
- C:\Oracle\sqlcl\lib\ucp.jar
- C:\Oracle\sqlcl\lib\xdb6.jar
- C:\Oracle\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\access-bridge-64.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\cldrdata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\dnsns.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jaccess.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jfxrt.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\localedata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\nashorn.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunec.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunjce_provider.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunmscapi.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunpkcs11.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\zipfs.jar
- C:\repos\odb\db-scripts
- C:\repos\odb\db-scripts\.
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
For more information, please use the --logLevel flag
Note that liquibase added the current directory on the lookup list. And that's why it managed to find my test.sql file. Looks like sqlcl is the one who fails to use the current path for SQL files.
I have the next project structure.
\rootProj
|
+--\moduleA
| |
| +--\build
| |--build.gradle
| ...
|
+--\moduleB
|
+--\main
| |
| +--\resources
| ...
|
|-build.gradle
...
I'm searching an approach to put everything from moduleA\build to moduleB\main\resources.
Could someone help me with this task?
I've googled about it but found nothing - I'm new in Gradle and it may be a cause I can't ask in the right way.
Thanks in advance!
As an answer to my question I've made the next solution:
buildscript{
ext{
generatedResOutDir = file("$buildDir/generated-resources")
}
}
sourceSets {
main{
output.dir(generatedResOutDir, builtBy: 'copyRes')
}
}
task copyRes(type: Copy){
//for to be certain a directory
//we are going to copy from
dependsOn ':moduleA:build'
from project(':moduleA').buildDir
into '${generatedResOutDir}/static'
}
This solution is inspiried by Gradle DSL SourceSetOutput doc.
I've the following gradle project structure:
SUPER/
|______A/
| |______A1/
| | |______build.gradle
| |______A2/
| | |______build.gradle
| |______build.gradle
| |______settings.gradle
|
|______B/
| |______build.gradle
| |______settings.gradle
|
|______build.gradle
|______settings.gradle
My build.gradle from the A-Project contains somethings like that:
...
project(":A1") {
apply plugin: "java-library"
dependencies {
api project(":A2")
}
}
project(":A2") {
apply plugin: "java-library"
dependencies {
...
}
}
...
My "Super"-settings.gradle file contains something like that:
rootProject.name = 'SUPER'
include 'A'
include 'B'
In my sub-project "A" the settings.gradle looks like that:
include 'A1', 'A2'
When calling the gradlewrapper like that "./gradlew SUPER:A1:sometask" on the command line from the SUPER-folder, it fails with the message:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\<somepath>\SUPER\A\build.gradle' line: 44
* What went wrong:
A problem occurred evaluating project ':A'.
> Project with path ':A1' could not be found in project ':A'.
But when doing something like that "./gradlew A1:sometask" from the A-sub-project-folder, it works successfully.
can you explain me what am I'm doing here wrong?
I'm using ESM to loading my modules and I use them in this way:
// More info on why this is needed see (https://github.com/mochajs/mocha/issues/3006)
async function wire(){
await import("./Sanity.spec.mjs");
await import("./Other.spec.mjs");
run();
}
wire();
I run these tests using nyc mocha --delay --exit ./test/suite.js, but when I run Istanbul it does not seems to recognize my imports and fails to provide coverage information...
3 passing (14ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
How can I get Istanbul to recognize the ESM loaded code?
Native ESM support is available from Mocha v7.1.0 (February 2020).
See:
Relase notes: https://github.com/mochajs/mocha/releases/tag/v7.1.0
Pull request: https://github.com/mochajs/mocha/pull/4038
I have a relatively complex directory structure in my build, from which I would like to create multiple ZIP files. The structure is like this:
+ project root
+ -- build.gradle
+ -- + foo
+ -- bar-1
| + -- bar-1.a.json
| + -- bar-1.a.xml
| + -- bar-1.b.json
| + -- bar-1.b.xml
|
+ -- bar-2
| + -- bar-2.a.json
| + -- bar-2.a.xml
| + -- bar-2.b.json
| + -- bar-2.b.xml
|
+ ...
+ -- bar-n
+ -- bar-n.a.json
+ -- bar-n.a.xml
+ -- bar-n.b.json
+ -- bar-n.b.xml
From this structure, I would like to create ZIP files for each bar-x directory, e.g. from foo/bar-1 directory, a ZIP file should be created in out/foo/bar-1.zip, from foo/bar-2 a ZIP file should be created in out/foo/bar-2.zip and so on
It is important, that new directories might appear later on, so I cannot hard-code the names, Gradle should list the directories in foo on each build.
Can someone give me a sample on how to achieve this?
Something like the following should do:
task zipAll
file('foo').eachDirMatch(~/bar-.*/) { barDir ->
def taskName = "zip${barDir.name.capitalize()}"
task "$taskName"(type: Zip) {
from barDir
destinationDir file('out/foo/')
baseName barDir.name
}
zipAll.dependsOn taskName
}