Spring properties: spring.config.additional-location not verriden property values - spring

I'm using this command line in order to start my service locally:
mvn -pl rep-digital-api clean compile spring-boot:run \
-Dspring-boot.run.arguments=--spring.config.additional-location=front-pre-props.properties
pre profile is activated since front-pre-props.properties contains spring.profiles.active=pre.
Into default application-dev.properties I've set this property:
api.path-web=web
Nevertheless, I need to simulate pre profile into my local environment. So I need to change this property value:
api.path-web=other-path
Nevertheless, this property is not overriden.
Also I've tested it seting -Dapi.path-web=other-value in to mvn command, but it doesn't work...
Any ideas?

If you are trying to add a file from the file system, you need to set the value of property spring.config.additional-location to file:/pathtofile/yourfile.properties.
Lets say your file front-pre-props.properties is in path /Users/demo/front-pre-props.properties
Then you can execute the run command as :
mvn -pl rep-digital-api -Dspring.config.additional-location=“file:/Users/demo/front-pre-props.properties” clean compile
spring-boot:run

Related

Maven project execute without ide

I do a selenium test using Maven. I have more than 20 test classes. How do I export and run them without ide ?
I am also using the POM structure.
Simply open terminal/cmd, navigate to you project directory and use maven command:
mvn clean test
clean — delete target directory
test — run tests
If you want to specify which exactly class you want to run (no all like above) you can run a -Dtest parameter like suggested:
mvn clean -Dtest=testClass install
First navigate to folder where your project's pom.xml is located.
cd DirectoryWherePOMisLocated
then execute below command,
mvn clean -Dtest=classNameWhichYouWantToExecute install
If you want to execute multiple classes just separate them with , in -Dtest argument.
Hope this helps!!

Jenkins: Pass multiple MAVEN profiles via user selection

following situation: I want to build a maven project via jenkins and also be able to select multiple maven profiles (to be precise it has to build with two profiles, one of those is a fixed value called 'dev', so basically I want to be able to select the second profile from a list of profiles) before building, so a parameterized build. I add the selectable profile as a option-list and now I'm able to select it from a dropdown, so far, so good.
BUT: It seems the problem is the multiple profile part.
In the maven goal-field I type
clean install -Pdev,$Client
with 'Client' being the parameter for the build which contains the selected value.
But if I start the build, the command line says e.g.
mvn clean install "-Pdev,test"
with the problem being it wrapping the Profiles in apostrophes. If I test it with a single parameter it works as expected:
clean install -P$Client
Based on the following explanation, try some of these:
#1 mvn install -P profile1,profile2
#2 mvn install -Pprofile1 -Pprofile2
#3 mvn install -P 'profile1,profile2'
Explanation
According to official documentation
https://maven.apache.org/guides/introduction/introduction-to-profiles.html
The correct multi profile invocation is :
mvn groupId:artifactId:goal -P profile1,profile2
And some variations are allowed:
https://stackoverflow.com/a/16792775/3957754
https://stackoverflow.com/a/42766252/3957754
mvn install -Pprofile1 -Pprofile2
Ans as always :s an special treatment for windows:
mvn install -P 'profile1,profile2'

How to pass more than one argument in the same property in maven command line

I'm trying to run automation test using maven command.
my property for running a specific test is -DtestsToExecute
I can run a single test by passing the test name to this property:
mvn clean verify -DtestsToExecute=UITest
How can I run more than one test at once? I mean how can I pass more than one argument to the same property? I've tried putting comma between the different tests name, but with no success:
mvn clean verify -DtestsToExecute=UITest1,UITest2

-Dmaven.multiModuleProjectDirectory system property is not set in JDeveloper 12.1.3 and external maven

In JDeveloper 12.1.3 get 'suddenly' follwing error when running any maven goal on a random Java application. I mean suddenly, because i use JDeveloper infrequently for making modifications to Java classes and do not have full control over my Development environment. (Managed by admins).
Most important env variables are;
M2 = %M2_HOME%\bin
M2_HOME = D:\Tools\apache-maven-3.3.9
MAVEN_HOME = D:\Tools\apache-maven-3.3.9
MAVEN_OPTS = -Xms256m -Xmx512m -Dmaven.multiModuleProjectDirectory=%MAVEN_HOME%
I also tried enclose %MAVEN_HOME% in double quotes.
Maven preferences in JDeveloper are
Maven Version, external version: D:\Tools\apache-maven-3.3.9
User settings: D:\Tools\apache-maven-3.3.9\conf\settings.xml
Additional settings: -X -DdownloadSources=true -DdownloadJavadocs=true -P deploy-to-local-server -Dmaven.multiModuleProjectDirectory=D:\Tools\apache-maven-3.3.9
Local Repository: D:\Tools\Apache\maven3_repository
Index Directory: D:\Tools\Apache\maven3_index
All settings seems to be ok. When running mvn from the commandline, e.g. mvn test --settings D:\Tools\apache-maven-3.3.3\conf\settings.xml the build completes successfully.
Als tried to set the Java property in the jdev.conf AddVMOption -Dmaven.multiModuleProjectDirectory="%MAVEN_HOME%"
If the mvn goal test is chosen in JDeveloper it executes the command;
D:\Oracle\Java\jdk1.7.0_45\bin\javaw.exe -classpath D:\Tools\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-provider-api-2.10.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-http-shared-2.10.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-http-2.10-shaded.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-file-2.10.jar;D:\Tools\apache-maven-3.3.9\lib\slf4j-simple-1.7.5.jar;D:\Tools\apache-maven-3.3.9\lib\slf4j-api-1.7.5.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-utils-3.0.22.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-sec-dispatcher-1.3.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-interpolation-1.21.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-component-annotations-1.6.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-cipher-1.7.jar;D:\Tools\apache-maven-3.3.9\lib\org.eclipse.sisu.plexus-0.3.2.jar;D:\Tools\apache-maven-3.3.9\lib\org.eclipse.sisu.inject-0.3.2.jar;D:\Tools\apache-maven-3.3.9\lib\maven-settings-builder-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-settings-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-repository-metadata-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-plugin-api-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-model-builder-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-model-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-embedder-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-core-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-compat-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-builder-support-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-artifact-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-aether-provider-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\jsr250-api-1.0.jar;D:\Tools\apache-maven-3.3.9\lib\jsoup-1.7.2.jar;D:\Tools\apache-maven-3.3.9\lib\javax.inject-1.jar;D:\Tools\apache-maven-3.3.9\lib\guice-4.0-no_aop.jar;D:\Tools\apache-maven-3.3.9\lib\guava-18.0.jar;D:\Tools\apache-maven-3.3.9\lib\commons-lang3-3.4.jar;D:\Tools\apache-maven-3.3.9\lib\commons-lang-2.6.jar;D:\Tools\apache-maven-3.3.9\lib\commons-io-2.2.jar;D:\Tools\apache-maven-3.3.9\lib\commons-cli-1.2.jar;D:\Tools\apache-maven-3.3.9\lib\cdi-api-1.0.jar;D:\Tools\apache-maven-3.3.9\lib\aopalliance-1.0.jar;D:\Tools\apache-maven-3.3.9\lib\aether-util-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-transport-wagon-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-spi-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-impl-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-connector-basic-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-api-1.0.2.v20150114.jar; -Dclassworlds.conf=D:\Tools\apache-maven-3.3.9\bin\m2.conf -Dmaven.home=D:\Tools\apache-maven-3.3.9 org.codehaus.classworlds.Launcher -X -DdownloadSources=true -DdownloadJavadocs=true -P deploy-to-local-server -Dmaven.multiModuleProjectDirectory=D:\Tools\apache-maven-3.3.9 --settings D:\Tools\apache-maven-3.3.9\conf\settings.xml --file C:\Projecten\project\A\B\pom.xml clean -Denv.ORACLE_HOME=D:\Oracle\Middleware_JDev12.1.3
When executing this command on the commandline it completes, but does not seem to execute to goal. If javaw is replace with java it shows the error -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match. again. As can be seen in de command extract above, the system property is set.
Any other suggestions ?
Downgrading Maven to 3.1.1 resolved the issue. For now this is a solution for me.

Are spring-boot command line properties available when using spring-boot:run?

The short question:
How can you configure environment profiles, or even just an alternative configuration file name for
spring-boot:run?
The long version:
Yes, I read the doc. http://docs.spring.io/spring-boot/docs/current/reference/html/index.html
I have my application configuration settings in src/main/resources/application-mysql.properties:
# Specify the DBMS
spring.jpa.database = MYSQL
# Other Mysql config properties
spring.jpa.hibernate.ddl-auto=create
There is a corresponding application-hsql.properties, which contains the same set of configuration options for Hsql.
There is no application.poperties
There is a corresponding import.sql:
insert into users(name, email) values ('User One', 'one#email.com')
insert into users(name, email) values ('Two User', 'two#email.com')
The unit tests exist only to check for the presence of these users in the repo.
I believe it to be true that whenever the test is run using the MySql configuration, those rows are added to the users table. When the test is run with hsql, the mysql db should be unaffected.
I am manually dropping the users table between runs, because I want to manually see when it exists.
1) If I run mvn test, the tests use the configured db:
mvn -Dspring.profiles.active=mysql clean test
Produces mysql database rows and
mvn -Dspring.profiles.active=hsql clean test
Does not.
2) If I make a package, and then run the resulting jar file, I am able to specify a config file name:
java -jar -Dspring.profiles.active=mysql ./target/app.jar
3) If I run with spring-boot:run, only properties in application.properties (which doesn't exist in this test scenario) are discovered.
mvn -Dspring.profiles.active=mysql clean spring-boot:run
What does spring-boot:run do differently in launching than running unit tests and kicking off the jar? The db config is one example, but in theory I'd like to be able to specify a set of dev configs when the application is being run locally vs. a production configuration.
The Maven spring-boot plugin forks a new process so you'll need to send any extra parameters to it via jvmArguments, e.g.:
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=mysql"
The plugin allows you to specify the active profile(s) directly (perhaps it wasn't the case 3 year ago?) :
mvn spring-boot:run -Drun.profiles=mysql

Resources