0

I'm trying to execute a maven command like the following:

mvn clean install -f ../<some-path>/pom.xml -Pear -DskipTests

For some reason this command is not working correctly. The profile is not getting applied. What is the problem here?

Saltuk Kezer
  • 105
  • 1
  • 7
  • Have you tried to set `clean install` at the end of the command? `mvn -f ..//pom.xml -Pear -DskipTests clean install` – Turing85 Dec 23 '21 at 14:57
  • is the profile available/visible/known to `//pom.xml` ? otherwise maven console should output: `[WARNING] The requested profile "ear" could not...`, if the profile is properly applied, it should also be visible in the logs... – xerx593 Dec 23 '21 at 15:01
  • I think you need a space between -P and the profile you want to run. The command should work, so are you 100% sure the file is being picked up. Add -X to the command you'll get more detail. – emeraldjava Dec 23 '21 at 15:02
  • is there reason why you call maven via `../..` instead of moving into the appropriate directory ? – khmarbaise Dec 23 '21 at 15:04
  • So the actual thing is that i'm trying to execute the mvn clean install from a folder that is a subfolder of the project folder. But it doesn't work like i'm trying it. If i navigate to the project folder it works (without the -f). The command is also working, the profile is just not getting applied. xerx593 I'm not getting an error, Turing85 didn't help, emeraldjava I will try the -X – Saltuk Kezer Dec 23 '21 at 15:07
  • @khmarbaise I'm trying to running it via an automated script that is in a subfolder of the project – Saltuk Kezer Dec 23 '21 at 15:07
  • The command looks(*is*) ok! If you don't get [WARNING], then profile is applied! (your assumptions/expectations/observations could be wrong, or some ( thing/profile) interferes..?) – xerx593 Dec 23 '21 at 15:10
  • What do you mean by running within a subfolder ? First get it working on plain command line and afterwards automate it... – khmarbaise Dec 23 '21 at 15:13

2 Answers2

1

I think maybe -f doesn't work as you think it does. See this answer: How to run Maven from another directory (without cd to project dir)?

If your project uses relative pom locations, this breaks.

See also: https://maven.apache.org/plugin-developers/common-bugs.html#Resolving_Relative_Paths

Adriaan Koster
  • 15,870
  • 5
  • 45
  • 60
0
cd ..
call mvn -DskipTests -Pear clean install
cd <some-path>

I did it like this now and it works. Thanks for @Adriaan Koster for the hint with the relative poms. That seems to have been it. And maybe i should use absolute paths instead :)

Saltuk Kezer
  • 105
  • 1
  • 7