Skip to content

Commit ab9480c

Browse files
committed
fix: exclude standalone examples from mise run format
Standalone example POMs don't inherit the spotless plugin from the project parent, so `spotless:apply` fails when they're in the reactor (JDK 25+ activates the examples-and-integration-tests profile). Use the fully-qualified plugin goal with profile deactivation to skip these modules. Add a `lint:example-poms` check to catch this class of issue in the future. Fixes #1927 Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent b9906c1 commit ab9480c

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

.mise/tasks/lint/example-poms.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
3+
# [MISE] description="Verify standalone example POMs won't break spotless"
4+
5+
"""Check that standalone example modules don't break 'mise run format'.
6+
7+
Example modules are intentionally standalone (no <parent> from the project)
8+
so users can copy them. But they're included in the Maven reactor via the
9+
examples-and-integration-tests profile. If 'mise run format' doesn't
10+
exclude them, spotless:apply fails because the plugin isn't declared.
11+
12+
This lint verifies that every standalone example POM is excluded from
13+
the format task in mise.toml.
14+
"""
15+
16+
import re
17+
import sys
18+
from pathlib import Path
19+
20+
ROOT = Path(__file__).resolve().parents[3]
21+
EXAMPLES_DIR = ROOT / "examples"
22+
23+
24+
def find_standalone_example_poms() -> list[Path]:
25+
"""Find example pom.xml files that don't inherit from the project parent."""
26+
standalone = []
27+
for pom in sorted(EXAMPLES_DIR.rglob("pom.xml")):
28+
if "target" in pom.parts:
29+
continue
30+
text = pom.read_text(encoding="utf-8")
31+
# Check if this POM has a <parent> with the project's groupId/artifactId
32+
has_project_parent = bool(
33+
re.search(
34+
r"<parent>\s*<groupId>io\.prometheus</groupId>\s*"
35+
r"<artifactId>client_java</artifactId>",
36+
text,
37+
)
38+
)
39+
if not has_project_parent:
40+
standalone.append(pom)
41+
return standalone
42+
43+
44+
def format_task_excludes_examples() -> bool:
45+
"""Check that the format task in mise.toml excludes standalone examples."""
46+
mise_toml = ROOT / "mise.toml"
47+
text = mise_toml.read_text(encoding="utf-8")
48+
# Look for the format task run command
49+
match = re.search(
50+
r'\[tasks\.format\].*?run\s*=\s*"([^"]*)"', text, re.DOTALL
51+
)
52+
if not match:
53+
return False
54+
run_cmd = match.group(1)
55+
# The command should deactivate the examples-and-integration-tests profile
56+
return "!examples-and-integration-tests" in run_cmd
57+
58+
59+
def main() -> int:
60+
standalone = find_standalone_example_poms()
61+
if not standalone:
62+
return 0
63+
64+
if format_task_excludes_examples():
65+
return 0
66+
67+
print("ERROR: Standalone example POMs found but 'mise run format'")
68+
print("does not exclude the examples-and-integration-tests profile.")
69+
print()
70+
print("Standalone example POMs (no project parent):")
71+
for pom in standalone:
72+
print(f" {pom.relative_to(ROOT)}")
73+
print()
74+
print("Fix: ensure the format task in mise.toml deactivates the")
75+
print("examples-and-integration-tests profile, e.g.:")
76+
print(" -P '!examples-and-integration-tests'")
77+
return 1
78+
79+
80+
if __name__ == "__main__":
81+
sys.exit(main())

mise.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ env.PROTO_GENERATION = "true"
2020

2121
[tasks.format]
2222
description = "format source code"
23-
run = "./mvnw spotless:apply"
23+
# Use fully-qualified plugin goal and deactivate the examples-and-integration-tests
24+
# profile because standalone example modules don't inherit the spotless plugin.
25+
run = "./mvnw com.diffplug.spotless:spotless-maven-plugin:apply -P '!examples-and-integration-tests'"
2426

2527
[tasks.clean]
2628
description = "clean all modules"
@@ -65,7 +67,7 @@ file = "https://raw.githubusercontent.com/grafana/flint/0ac131d7832bd8964f6ca9e5
6567

6668
[tasks."lint"]
6769
description = "Run all lints"
68-
depends = ["lint:super-linter", "lint:links", "lint:bom", "lint:renovate-deps"]
70+
depends = ["lint:super-linter", "lint:links", "lint:bom", "lint:example-poms", "lint:renovate-deps"]
6971

7072
[tasks.fix]
7173
description = "Auto-fix lint issues"

0 commit comments

Comments
 (0)