Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use PostgreSQL in Maven build?

I am trying to create an integration test, which requires a running PostgreSQL server. Is it possible to start the server in maven build and stop it when tests are completed (in a separate process, I think)? Assuming the PostgreSQL server is not installed on the machine.

like image 319
yegor256 Avatar asked Dec 09 '25 02:12

yegor256


1 Answers

You are trying to push maven far beyond the intended envelope, so you'll be in for a fair amount of hurt before it will work.

Luckily postgresql can be downloaded as a zip archive.

As already mentioned above maven can use ant tasks to extend its reach. Ant has a large set of tasks to unzip files, and run commands. The sequence would be as follows :

  • unzip postgresql-xxx.zip in a well known directory --> INSTALL_DIR
  • create a data directory --> DATA_DIR
  • /bin/init-db -D
  • /bin/postgres -D
  • /bin/create_db -EUNICODE test

This should give you a running server with a test database.

Further issues : create a user, security (you likely want to connect via TCP/IP but this is disabled by default if I recall correct, this requires editing a config file before starting the database)

...

Good Luck.

like image 194
Peter Tillemans Avatar answered Dec 10 '25 16:12

Peter Tillemans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!