Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'libraries' is misspelled or does not exist. #169

Closed
dmitry-weirdo opened this issue Jan 4, 2023 · 5 comments
Closed

Property 'libraries' is misspelled or does not exist. #169

dmitry-weirdo opened this issue Jan 4, 2023 · 5 comments

Comments

@dmitry-weirdo
Copy link

dmitry-weirdo commented Jan 4, 2023

According to these warnings

Property 'style>ForbiddenPublicDataClass' is deprecated. Rule migrated to `libraries` ruleset plugin.
Property 'style>LibraryCodeMustSpecifyReturnType' is deprecated. Rule migrated to `libraries` ruleset plugin.
Property 'style>LibraryEntitiesShouldNotBePublic' is deprecated. Rule migrated to `libraries` ruleset plugin.

I moved these rules to libraries, which is conforming to detekt-1.22.0.json:

libraries:
  active: true

  ForbiddenPublicDataClass:
    active: true
    excludes: [ '**' ]
    ignorePackages:
      - '*.internal'
      - '*.internal.*'

  LibraryCodeMustSpecifyReturnType:
    active: true
    excludes: [ '**' ]

  LibraryEntitiesShouldNotBePublic:
    active: true
    excludes: [ '**' ]

But the plugin execution is now falling with

[ERROR] Failed to execute goal com.github.ozsie:detekt-maven-plugin:1.22.0:check (default) on project rss-app: Execution default of goal com.github.ozsie:detekt-maven-plugin:1.22.0:check failed: Run failed with 2 invalid config properties.
[ERROR]         - Property 'libraries' is misspelled or does not exist.

The same happens if I add formatting rules:

- Property 'formatting' is misspelled or does not exist.

Related issues

detekt/detekt#5360 — this seems to be the PR where these rules have been refactored.

detekt/detekt#5548 — this says it should provide examples for avoiding this, but it will be gradle plugin, not maven plugin.

I think the updated doc link is here — https://detekt.dev/docs/next/rules/libraries/.

and it says

Note: The libraries rule set is not included in the detekt-cli or Gradle plugin.

To enable this rule set, add detektPlugins "io.gitlab.arturbosch.detekt:detekt-rules-libraries:$version" to your Gradle dependencies or reference the detekt-rules-libraries-jar with the --plugins option in the command line interface.

detekt/detekt#5304 — this issue says that we have to add more gradle dependencies eg for formatting, but how to do this when using the maven plugin?

How should we add the non-default rulesets when using the maven plugin?

@TWiStErRob
Copy link
Contributor

You need to add the libraries artifact just like any other third party ruleset.

See "To enable this rule set" paragraph in the docs

There are two first party rulesets not included by default:

@TWiStErRob
Copy link
Contributor

I haven't used this Maven plugin, but looking at the readme, I think this is the section you need: https://github.com/Ozsie/detekt-maven-plugin#using-plugin, the second code block with dependencies.

@dmitry-weirdo
Copy link
Author

@TWiStErRob thank you, but it is still not clear how to add those rulesets when running via maven plugin.

I tried this, it does not help:

    <dependency>
      <groupId>io.gitlab.arturbosch.detekt</groupId>
      <artifactId>detekt-rules-libraries</artifactId>
      <version>${detekt-maven-plugin.version}</version> <!-- this is 1.22.0 -->
      <scope>runtime</scope>
    </dependency>

@TWiStErRob
Copy link
Contributor

Is it inside the plugins block?

@dmitry-weirdo
Copy link
Author

dmitry-weirdo commented Jan 4, 2023

@TWiStErRob yes, the problem was that I was putting the dependencies in the artifact dependencies instead of plugin dependencies.

It Is working now, thanks a lot for pointing me to this doc block. 👍

My plugin configuration now looks like this:

      <plugin>
        <groupId>com.github.ozsie</groupId>
        <artifactId>detekt-maven-plugin</artifactId>
        <version>${detekt-maven-plugin.version}</version>
        <configuration>
          <baseline>.mvn/baseline-rss-app.xml</baseline>
          <config>detekt.yml</config>
        </configuration>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>

        <!-- enable "libraries" ruleset -->
        <!-- see https://github.com/Ozsie/detekt-maven-plugin/issues/169 -->
        <dependencies>
          <dependency>
            <groupId>io.gitlab.arturbosch.detekt</groupId>
            <artifactId>detekt-rules-libraries</artifactId>
            <version>${detekt-maven-plugin.version}</version>
            <scope>runtime</scope>
          </dependency>
        </dependencies>
      </plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants