Is it possible to generate change log using generateChangeLog command for non default user schema. I've tried to do it using defaultSchemaName argument but it it didn't worked out. Liquibase is throwing
java.lang.RuntimeException: Cannot use default schema name myschema on M
icrosoft SQL Server because the login schema of the current user (dbo) is different and MSSQL does not support setting the default schema per session.
I've also tried to use maven plugin but only dbo schema has been dumped. Plugin configuration looks like follows:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<propertyFile>src/main/liquibase.properties</propertyFile>
<changelogSchemaName>mySchema</changelogSchemaName>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
In my case I was able to get liquibase-maven-plugin to process a different schema via the property defaultSchemaName, which I put into a liquibase.properties file, referenced from the POM.
defaultSchemaName: EXAMPLE
I tried other properties with no luck.
Related
I've joined a project that has a lot of files with SQL statements for creating a database that is used for integration testing.
I'm wondering how I can use these files to create a database for unit testing
(using java and maven).
I can create a HSQL in-memory database for each unit test, or even use the spring jdbc embedded-database feature, but there's so many SQL statements to execute in the test setup that this is not scalable.
So I'd like to create a temporary database (that loads the SQL statements) at the start of the maven test phase, have the unit tests access this temporary database and perform various operations, then delete the temporary database at the end of the maven test phase.
I've looked at sql-maven-plugin which would allow me to do the test phase executions, but I'm not sure how to configure a temporary database that will be available across all unit tests. There's no server to connect to, and in-memory database will not work across multiple unit tests (I assume).
One option could be to use a unique temporary file, e.g. specifying the JDBC driver URL as jdbc:hsqldb:file:/path/to/temporary/file, but I'm not sure how to generate a unique temporary file in maven.
Any suggestions on how to do this, or if there's a better approach to take?
Update: I decide to use a file-based database created in target/db directory. I use the maven clean plugin to remove the target/db directory before tests are run, and the maven sql plugin to create the database from scripts.
For this case I have created the derby-maven-plugin. It's available from Maven Central, so you don't need to add any extra repositories or anything.
You could use it like this:
<project ...>
<build>
<plugins>
<plugin>
<groupId>org.carlspring.maven</groupId>
<artifactId>derby-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<basedir>${project.build.directory}/derby</basedir>
<port>1527</port>
</configuration>
<executions>
<execution>
<id>start-derby</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-derby</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
For more info you can also check the USAGE.
Why not create an on-disk H2 database, and have each test access it? So long as the tests don't run in parallel or interact with each other, you don't need a server.
Even more so: just create memory databases in #Before and delete them in #After. Are you sure that's too slow?
In pre-integration-test, you could launch an H2 (or derby) server, and shut it down in post-integration-test.
You can write a maven plugin that uses session state to keep track of an embedded database service, but that's much the same as (3).
I want to put the hibernate3-maven-plugin in my parent pom and have execution skipped in child modules if a given file does not exist in that module.
Is there any way to do this?
Up to now, I have had to do this:
<plugin>
...
<configuration>
<skip>true</skip>
<propertyfile>target/test-classes/jdbc.properties</propertyfile>
</configuration>
</plugin>
In the parent POM, and:
<plugin>
...
<configuration>
<skip>${maven.test.skip}</skip>
</configuration>
</plugin>
In all child POMs where I want it to execute. I.E Those actually having a jdbc.properties file.
You may be able to do this with profiles, but I suppose you'd probably not want to run it in the parent project, which may be problematic.
Here are some links on profiles:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
http://www.sonatype.com/books/mvnref-book/reference/profiles.html
http://mindthegab.com/2008/12/02/howto-give-your-multimodule-maven-build-subprojectenvironment-specific-behavior/
This question, had a similar issue and was not able to solve it with profiles:
activate-different-maven-profiles-depending-on-current-module
I'm not 100% on the logistics but you could possibly use the maven exec plugin in combination with a shell script. The shell script would check for the presence of the file and then invoke the mvn plugin using the maven pom directory - which can be obtained and passed to the shell script via the Maven environment variables.
I am setting up maven to take annotated java classes and produce some DDL which varies depending on the database. Is there a better way to do this? It seems like I should be able to filter the input to the hbm2ddl plugin (as part of a pipeline) rather than tell it to operate on the output of resource filtering (which I then must filter out of my final jar).
I am filtering my hibernate.cfg.xml file to substitute environment properties based on the local developer's setup:
<build>
<filters>
<filter>${user.home}/datamodel-build.properties</filter>
</filters>
<resources><resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource></resources>
</build>
Then I run hbm2ddl on the output
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
...
<configuration>
<componentProperties>
<configurationfile>target/classes/com/myOrg/datamodel/hibernate.cfg.xml</configurationfile>
</plugin>
I then must filter out the hibernate.cfg.xml from my production jar since I don't want to ship anything related to my internal dev environment.
I have this same issue and here is how I solved it. I use have a separate database.properties file that holds the connection details and I don't filter any of my XML files.
This seperate database.properties file gets filtered, but since it is a test resource located in /src/main/test it doesn't get put into the final artifact. I then tell hbm2ddl where to find it as follows:
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>jpaconfiguration</implementation>
</component>
</components>
<componentProperties>
<propertyfile>src/test/resources/database.properties</propertyfile>
<!-- Gives the name of the persistence unit as defined in persistence.xml -->
<persistenceunit>myapp-core</persistenceunit>
<!-- Tells the plugin to send the output to a file -->
<outputfilename>create-${database.vendor}-schema.sql</outputfilename>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Do not create tables automatically - other plug-ins will handle that -->
<export>false</export>
<!-- Do not print the DDL to the console -->
<console>false</console>
</componentProperties>
</configuration>
Hope it helps anyway....
I am using checkstyle plugin in maven 2. I now want to switch my config file, from the default one to a) an online file, or b) a local file. I tried the following two things, which both didnt work. Any suggestions?
A) Local file, which is directly in my project folder next to the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
B) Remote file, that is stored on a server
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>http://stud.hs-heilbronn.de/~nischmid/development/checkstyle-config.xml</configLocation>
</configuration>
</plugin>
Both cases result in an error like this:
[INFO] An error has occurred in
Checkstyle report generation. Embedded
error: Failed during checkstyle
execution Could not find resource
'file:checkstyle.xml'.
Any help would be appreciated!
I've seen several issues related to configLocation in Jira with the version 2.5 of the plugin (like MCHECKSTYLE-129 or MCHECKSTYLE-131), both a) and b) just work fine with the version 2.4.
So, unless you're using Maven 3, I suggest to rollback to 2.4 for now:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugins>
or
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<configLocation>http://stud.hs-heilbronn.de/~nischmid/development/checkstyle-config.xml</configLocation>
</configuration>
</plugin>
As a side note, for a multi-modules build, have a look at the Multimodule Configuration.
I've been trying to use version 3.0.1 of the Checkstyle plugin and found configLocation has no effect. Tried the approach above, but still no luck.
To summarise, the answer above probably does work, but you might need to set a property checkstyle.config.location.
Using -X to get debug output, I saw:
[DEBUG] (f) configLocation = config/sun_checks.xml
Scrolling further back in the log, it looks like configLocation isn't being set:
<configLocation default-value="config/sun_checks.xml">${checkstyle.config.location}</configLocation>
Based on that message, I set the property in the global <properties> as follows:
<checkstyle.config.location>${basedir}/config/checkstyle-configuration.xml</checkstyle.config.location>
This worked, but caused the plugin to throw an exception. After some Googling, I added the following to the checkstyle configuration file:
<module name="Checker">
...
<module name="TreeWalker">
...
<property name="cacheFile" value=""/>
For completeness, the last step came from the following Jira, marked as resolved in 2.8. The difference is it seems to work with an empty value, avoiding the need to set up a ${cachefile} property:
http://jira.codehaus.org/browse/MCHECKSTYLE-159
Maybe helpful for someone else who needs to still find a workaround.
By the way i had the same problem and the file is suppose to be searched in /classes/.xml or folders from here. But since it is looking directly after the project folder i included
<configuration>
<configLocation>src\main\resources\checkstyle-checker-dev.xml</configLocation>
</configuration>
Note: configLocation has L caps
Also you can define a global variable in environment and use here
Note: This is only a workaround, it needs to work as stated in the above lines.
I'm writing a test for a file parser class. The parse method receives a file name as parameter, and must open it in order to parse it ( duh ).
I've writen a test file, that I put into the test/resources directory inside my project directory, and would like to pass this file to test my parse. Since this project is in CVS, and will be manipulated by others, I can't hard code the file path, so I thought about use the maven ${basedir} property to build the file name in my test. Something like:
public void parseTest() {
...
sut.parse( ${basedir} + "src/test/resources/testFile" );
...
}
Does someone knows how could I achieve this?
You have 2 options:
1) Pass the file path to your test via a system property (docs)
In your pom you could do something like:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<systemProperties>
<property>
<name>filePath</name>
<value>/path/to/the/file</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
Then in your test you can do:
System.getProperty("filePath");
2) Put the file inside src/test/resources under the same package as your test class. Then you can get to the file using Class.getResourceAsStream(String fileName) (docs).
I would highly recommend option 2 over option 1. Passing things to your tests via system properties is very dirty IMO. It couples your tests unnecessarily to the test runner and will cause headaches down the road. Loading the file off the classpath is the way to go and that's why maven has the concept of a resources directory.