Giter Club home page Giter Club logo

bazel_rules_pmd's Introduction

bazel_rules_pmd

The PMD (a static analysis tool) integration for the Bazel build system.

Usage

MODULE.bazel Configuration

bazel_dep(name = "rules_pmd", version = "...")

WORKSPACE Configuration

Declare the rule in the WORKSPACE file. Please refer to GitHub releases for the version and the SHA-256 hashsum.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_pmd_version = "REPLACE_ME"
rules_pmd_sha = "REPLACE_ME"

http_archive(
    name = "rules_pmd",
    sha256 = rules_pmd_sha,
    strip_prefix = "bazel_rules_pmd-{v}".format(v = rules_pmd_version),
    url = "https://github.com/buildfoundation/bazel_rules_pmd/archive/v{v}.tar.gz".format(v = rules_pmd_version),
)

load("@rules_pmd//pmd:dependencies.bzl", "rules_pmd_dependencies")
rules_pmd_dependencies()

load("@rules_pmd//pmd:toolchains.bzl", "rules_pmd_toolchains")
rules_pmd_toolchains()

BUILD Configuration

Once declared in the WORSKPACE file, the rule can be loaded in the BUILD file.

load("@rules_pmd//pmd:defs.bzl", "pmd_test")

pmd_test(
    name = "pmd_analysis_test",
    srcs = glob(["src/main/java/**/*.java"]),
)

PMD Version

Change the MODULE.bazel file:

pmd = use_extension("//pmd:extensions.bzl", "pmd")
pmd.pmd_version(
    version = "x.x.x",
    sha256 = "x.x.x.sha256",
)
use_repo(pmd, "net_sourceforge_pmd")

Or change the WORKSPACE file:

load("@rules_pmd//pmd:versions.bzl", "pmd_version")
load("@rules_pmd//pmd:dependencies.bzl", "rules_pmd_dependencies")

rules_pmd_dependencies(
    pmd_version = pmd_version(
        version = "x.x.x",
        sha256 = "x.x.x.sha256",
    )
)

See available attributes.

Execution

$ bazel build //YOUR_PACKAGE:pmd_analysis

bazel_rules_pmd's People

Contributors

artem-zinnatullin avatar arturdryomov avatar bencodes avatar davidkurkov avatar dependabot[bot] avatar jmeekhof avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

bazel_rules_pmd's Issues

Issue with PMD rules

Hi,
While pulling our latest infra_versions, the bazel pinning started failing with the following error:

022-02-15 17:16:28,926 INFO executing "['/Users/abjain/Library/Caches/bazelisk/downloads/bazelbuild/bazel-4.2.1-darwin-x86_64/bin/bazel', 'run', '@unpinned_maven//:pin']"
ERROR: While resolving toolchains for target @bazel_tools//src/tools/launcher:launcher: invalid registered toolchain '//toolchains:all': while parsing '//toolchains:all': no such package 'toolchains': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/abjain/Desktop/Workspace/voice-triage-api/toolchains
ERROR: Analysis of target '@unpinned_maven//:pin' failed; build aborted: invalid registered toolchain '//toolchains:all': while parsing '//toolchains:all': no such package 'toolchains': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/abjain/Desktop/Workspace/voice-triage-api/toolchains
INFO: Elapsed time: 1.596s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (2 packages loaded, 6 targets configured)
FAILED: Build did NOT complete successfully (2 packages loaded, 6 targets configured)
    Fetching @local_config_sh; Restarting.
    Fetching @local_jdk; Restarting.
    Fetching @remotejdk11_linux_toolchain_config_repo; fetching
2022-02-15 17:16:30,550 INFO return code 1

On removing the PMD based changes, it worked fine. AFAIU, the issue is with the rule generated by PMD //toolchains:all' which expect it to be a package in repo and missing @somewhere before it. Can you please check it? It is a cool tool and we don't want to get away from using it.

File collision with "srcs.txt"

When running the PMD rule more than once with a single source directory causes a file collision with srcs.txt.

ERROR: file 'auth-service/src/main/java/.../authservice/service/srcs.txt' is generated by these conflicting actions:
Label: //auth-service/src/main/java/.../authservice/service:user_pmd_report, //auth-service/src/main/java/.../authservice/service:jwt_pmd_report
RuleClass: pmd rule
Configuration: f157fdcaf05e7672fa1bf535fbb2c3edb004ce9e9a7f6d84d9bf031454e2fb64
Mnemonic: FileWrite
Action key: 8274f4374f26dddba4a25edfcfaf003f32996d2dfb3cd35097e84d723e5d44f8, ba07612739f0f83b2e8ec6b5e324ef73ecb2b85c16a0529114bcbc1d8532ce69
Progress message: Writing file auth-service/src/main/java/.../authservice/service/srcs.txt
PrimaryInput: (null)
PrimaryOutput: File:[[<execution_root>]bazel-out/darwin-fastbuild/bin]auth-service/src/main/java/.../authservice/service/srcs.txt
Owner information: //auth-service/src/main/java/.../authservice/service:user_pmd_report BuildConfigurationValue.Key[f157fdcaf05e7672fa1bf535fbb2c3edb004ce9e9a7f6d84d9bf031454e2fb64], //auth-service/src/main/java/.../authservice/service:jwt_pmd_report BuildConfigurationValue.Key[f157fdcaf05e7672fa1bf535fbb2c3edb004ce9e9a7f6d84d9bf031454e2fb64]
MandatoryInputs: are equal
Outputs: are equal
ERROR: com.google.devtools.build.lib.skyframe.ArtifactConflictFinder$ConflictException: com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for auth-service/src/main/java/.../authservice/service/srcs.txt, previous action: action 'Writing file auth-service/src/main/java/.../authservice/service/srcs.txt', attempted action: action 'Writing file auth-service/src/main/java/.../authservice/service/srcs.txt'
INFO: Elapsed time: 2.800s
INFO: 0 processes.

I think I can find a simple solution by using the rule's name parameter as part of the report's output artifacts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.