Maven: How to allow a certain operating system for construction?


I know I can require specific OS family using maven-enforcer-plugin like this:

                            You should use Unix to build this.

But can I define multiple OS (for example Unix and Windows) that can be used for build?

Can't find any straight way to do it, so I appreciate any workaround.

The main goal of the <requireOS> element is to make some instruction during build platform-dependent, i.e. you need to perform some action based on the current operation system, thus it won't make much sense if you define configure some plugins for some OS and discard others.

In that spirit, the <requireOS> does not allow for range restriction (you cannot define multiple OSs as: <requireOS>[windows,linux]</requireOS>).

Meanwhile you still can write your own custom rule inheriting the EnforcerRule and only make the build fail if the current Operating System is not into your custom rule required OSs range.

There is already an implemented a rule that I have used once. You can check the multiple-os-enforcer-rule project URL where you can find more details on how-to use the custom rule.

More on custom rules implementation can be found in the Maven Docs