mojohaus / extra-enforcer-rules

Extra Enforcer Rules
https://www.mojohaus.org/extra-enforcer-rules/
Apache License 2.0
73 stars 47 forks source link

enforceBytecodeVersion - ignoring optional dependencies #52

Closed sebthom closed 5 years ago

sebthom commented 6 years ago

It would be great to have an option to ignore optional dependencies.

khmarbaise commented 6 years ago

Maybe I misunderstand your issue? You can already define <ignoredScopes>..</ignoredScopes>...see the docs https://www.mojohaus.org/extra-enforcer-rules/enforceBytecodeVersion.html


<rules>
  <enforceBytecodeVersion>
    <maxJdkVersion>1.7</maxJdkVersion>
    <ignoredScopes>optional</ignoredScopes>
  </enforceBytecodeVersion>
</rules>
sebthom commented 6 years ago

Thanks for your quick answer! Unfortunately this doesn't seem to work. Probably because "optional" isn't a real dependency scope but a scope modifier as in:

<dependency>
    <groupId>net.bytebuddy</groupId>
    <artifactId>byte-buddy</artifactId>
    <version>1.8.11</version>
    <scope>compile</scope>
    <optional>true</optional>
</dependency>
khmarbaise commented 6 years ago

Ah sorry..misunderstanding on my side...

sebthom commented 6 years ago

Maybe an attribute for the ignoredScope tag can introduced. Something like <ignoredScope with-optional="true">compile</ignoredScope>

khmarbaise commented 6 years ago

attributes do not work in maven pom files... But this looks like a logical && between ignoredScopes and optional...so you have the use case say a dependency in scope compile which has optional:true and other dependencies in scope: test which have also optional:true ? I think a simple solution in the first step would be having a boolean saying ignoreOptional=true to ignore all dependencies which have optional:true? WDYT ?

sebthom commented 6 years ago

I basically only want to check the bytecode version of non-optional compile dependencies. I don't care about other scopes. So for my use case I don't require a flag to control that per scope. Something like <ignoreOptionalDependencies/> would be sufficient.

khmarbaise commented 6 years ago

So it could look like this:

<rules>
  <enforceBytecodeVersion>
    <maxJdkVersion>1.7</maxJdkVersion>
    <ignoreOptional>true</ignoreOptional>
  </enforceBytecodeVersion>
</rules>
sebthom commented 6 years ago

I think a more specific name would be useful. In ignoreOptional it may be unclear to users what the term "optional" refers to. Also think it should be plural. The meaning of ignoreClasses in contrast is pretty clear: Ignore one (or more) class files.

khmarbaise commented 6 years ago

Sure good point...so ignoreOptionals ?

sebthom commented 6 years ago

Works for me.

sebthom commented 6 years ago

@khmarbaise could you merge your changes into master and create a new release by any chance?

sebthom commented 5 years ago

@khmarbaise any ETA for merge?