xiaohongshu
xiaohongshu
maven-builder-for-foolish-language
Comprehensive Maven build strategies for mixed Java/Scala projects with parallel execution, intelligent test running, and targeted debugging workflows. Use this skill when user asks to build the project, run tests, compile code, clean build, run Maven commands, fix compilation errors, or analyze ...
Full skill instructions
This skill provides comprehensive Maven build strategies for mixed Java/Scala projects with emphasis on parallel execution, intelligent test running, and targeted debugging workflows.
All build commands use dynamic resource detection to optimize parallelism based on the current machine:
# CPU cores (for thread calculations)
CORES=$(nproc)
# Total memory in GB (rounded down)
TOTAL_MEM_GB=$(free -g | awk '/^Mem:/{print int($2)}')
# Calculate optimal thread counts (rounded down to integers)
THREADS_2C=$((CORES * 2)) # Aggressive: 2 threads per core
THREADS_1C=$CORES # Conservative: 1 thread per core
TEST_THREADS=$((CORES * 4)) # Test parallelism: 4 threads per core
# Memory allocation (50% of total, rounded down)
MAVEN_MEM_GB=$((TOTAL_MEM_GB / 2))
Inline command examples embed these calculations directly for single-line execution.
Use when starting fresh or after significant changes:
mvn clean compile -T $(($(nproc) * 2))
CRITICAL: When debugging compilation errors, ALWAYS skip tests to focus on making code compile:
mvn clean compile -T $(($(nproc) * 2)) -DskipTests
For incremental compilation debugging:
mvn compile -DskipTests
CRITICAL FOR BUILD ISSUES: When debugging compilation errors, ALWAYS skip tests to focus on making code compile:
mvn clean compile -T $(($(nproc) * 2)) -DskipTests
-DskipTests not -Dmaven.test.skip (the latter skips test compilation too)For routine compilation after code changes:
mvn compile -T $(nproc)
When .g4 files or other source generators are modified:
mvn generate-sources -T $(($(nproc) * 2))
mvn compile -T $(($(nproc) * 2)) afterwardDefault testing approach for comprehensive validation:
mvn -T $(nproc) test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4)) -DperCoreThreadCount=false
perCoreThreadCount=false because threadCount already includes core multiplicationtarget/surefire-reports/ with readable summaries-Dparallel=classes -DthreadCount=$(($(nproc) * 4)) if method-level parallelization causes issuesWhen tests fail and you need detailed diagnostics:
mvn -T $(nproc) surefire:test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4)) \
-Dsurefire.rerunFailingTestsCount=0 \
-DtrimStackTrace=false \
-Dsurefire.printSummary=true \
-Dsurefire.useFile=true \
-Dsurefire.reportFormat=xml
target/surefire-reports/*.xmltrimStackTrace=false: Full stack tracesprintSummary=true: Readable summary in consoleuseFile=true: Detailed output to filesTo re-run only failed tests from previous run:
mvn -T $(nproc) surefire:test -Dsurefire.rerunFailingTestsCount=0 -DrerunFailingTestsCount=0
For focused debugging of one specific test:
mvn test -Dtest=ClassName#methodName -DtrimStackTrace=false
* for wildcards, e.g., -Dtest=*IntegrationTestmvn test -Dtest=ClassName -DtrimStackTrace=false
Approval tests (also called golden master tests or snapshot tests) typically involve:
Traditional loop-based approach is sequential:
// Sequential - slow for many test cases
@Test
public void approvalTests() {
for (String testFile : loadTestFiles()) {
runApprovalTest(testFile);
}
}
Use JUnit 5 @ParameterizedTest with parallel execution:
@ParameterizedTest
@MethodSource("approvalTestCases")
@Execution(ExecutionMode.CONCURRENT)
void approvalTest(ApprovalTestCase testCase) {
// Each test case runs in parallel
String input = testCase.loadInput();
String expected = testCase.loadExpected();
String actual = processInput(input);
assertEquals(expected, actual,
"Approval test failed for: " + testCase.getName());
}
static Stream<ApprovalTestCase> approvalTestCases() {
// Load all test case files from resources
return loadApprovalTestFiles()
.map(ApprovalTestCase::fromFile);
}
For JUnit 4, use parallel test methods:
public class ApprovalTests {
private static List<ApprovalTestCase> TEST_CASES;
@BeforeClass
public static void loadTestCases() {
TEST_CASES = loadApprovalTestFiles();
}
// Generate one @Test method per approval test case
@Test public void approvalTest_001() { runTest(TEST_CASES.get(0)); }
@Test public void approvalTest_002() { runTest(TEST_CASES.get(1)); }
// ... etc, or use dynamic test generation
private void runTest(ApprovalTestCase testCase) {
String actual = processInput(testCase.getInput());
assertEquals(testCase.getExpected(), actual);
}
}
Best approach: Dynamic test generation with JUnit 5 @TestFactory:
@TestFactory
Stream<DynamicTest> approvalTests() {
return loadApprovalTestFiles()
.map(testCase -> DynamicTest.dynamicTest(
"Approval: " + testCase.getName(),
() -> {
String actual = processInput(testCase.getInput());
assertEquals(testCase.getExpected(), actual);
}
));
}
Then enable parallel execution in junit-platform.properties:
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.mode.classes.default=concurrent
Full parallel execution:
mvn test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
Debugging single approval test:
# For parameterized tests, specify the parameter
mvn test -Dtest="ApprovalTests#approvalTest*testCase001*" -DtrimStackTrace=false
# Or use display name filtering (JUnit 5)
mvn test -Dtest="ApprovalTests" \
-Djunit.jupiter.displayname.generator.default=org.junit.jupiter.api.DisplayNameGenerator\$Simple \
-DtrimStackTrace=false
Debugging specific subset of approval tests:
# Filter by test case name pattern
mvn test -Dtest="ApprovalTests#*edge_case*" -DtrimStackTrace=false
Recommended structure:
src/test/resources/
└── approval-tests/
├── basic/
│ ├── test_001_input.txt
│ ├── test_001_expected.txt
│ ├── test_002_input.txt
│ └── test_002_expected.txt
├── edge-cases/
│ ├── null_handling_input.txt
│ ├── null_handling_expected.txt
│ └── ...
└── regression/
└── bug_123_input.txt
└── bug_123_expected.txt
Phase 1: Refactor to parameterized tests (still sequential)
// Before: loop-based
@Test void allApprovalTests() { for(...) { ... } }
// After: parameterized (can run sequentially first)
@ParameterizedTest
@MethodSource("testCases")
void approvalTest(TestCase tc) { ... }
Phase 2: Enable parallelization
# Add to pom.xml or junit-platform.properties
# Then run with: mvn test -Dparallel=classesAndMethods
Phase 3: Verify and optimize
# Check test timings in XML reports
cd target/surefire-reports/
grep "time=" TEST-*.xml | sort -t'"' -k2 -n
mvn clean test -T $(($(nproc) * 2)) -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
mvn clean verify -T $(($(nproc) * 2)) -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
CRITICAL: After running Maven tests, ALWAYS check test results in this order:
First: Check console output for summary statistics (tests run, failures, errors, skipped)
If failures occurred: Read XML reports directly
# List all files with failures
grep -l "failures=\"[1-9]" target/surefire-reports/TEST-*.xml
# Then READ the specific XML files for failed tests
# Use the Read tool on: target/surefire-reports/TEST-ClassName.xml
For detailed failure analysis: Use the Read tool to read the full XML file:
target/surefire-reports/TEST-<ClassName>.xml<testcase> elements with <failure> or <error> subelementsAlternative: Read plain text reports (less detailed but more readable):
target/surefire-reports/<ClassName>.txtBest practice: Use grep to identify which test classes failed, then use the Read tool to read the corresponding TEST-*.xml files directly.
Find all failures:
grep -l "failures=\"[1-9]" target/surefire-reports/TEST-*.xml
View specific failed test details:
grep -A 20 "testcase.*FAILED" target/surefire-reports/TEST-ClassName.xml
Common patterns when tests fail in parallel but not sequentially:
When you encounter test failures:
Identify the failure pattern
mvn -T $(nproc) test -Dparallel=classes -DthreadCount=$(($(nproc) * 4))
Review XML output in target/surefire-reports/
Run failed tests with verbose output
mvn test -Dtest=FailedTest1,FailedTest2 -DtrimStackTrace=false
If multiple related failures, group analysis
Single test deep dive
mvn test -Dtest=SpecificTest#specificMethod -DtrimStackTrace=false -X
The -X flag enables debug output from Maven itself
Create regression test from debug code If you write a temporary test program to verify assumptions:
@Category(RegressionTest.class) or similarmvn clean compile -T $(($(nproc) * 2)) -DskipTests
mvn verify -DskipUnitTests -Dparallel=classes -DthreadCount=$(($(nproc) * 4))
mvn test -Dgroups=com.example.FastTests -Dparallel=classes -DthreadCount=$(($(nproc) * 4))
export MAVEN_OPTS="-Xmx$(free -g | awk '/^Mem:/{print int($2 / 2)}')g -XX:+UseG1GC"
mvn clean verify -T $(($(nproc) * 2)) -Dparallel=classes -DthreadCount=$(($(nproc) * 4))
For mixed Java/Scala projects:
mvn scala:compile -T $(($(nproc) * 2))
mvn clean scala:compile compile -T $(($(nproc) * 2))
Check that <configuration> includes parallel compilation:
<recompileMode>incremental</recompileMode>
CRITICAL DEBUGGING PRINCIPLE: When you have compilation errors, ALWAYS skip tests. Tests cannot run if code doesn't compile.
Solution: Focus exclusively on making code compile first:
# Step 1: Skip tests, focus on compilation
mvn clean compile -T $(($(nproc) * 2)) -DskipTests
# Step 2: Fix compilation errors iteratively
mvn compile -T $(nproc) -DskipTests
# Step 3: Only after compilation succeeds, run tests
mvn test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
Why this matters:
Common scenario:
# ❌ WRONG: Trying to build and test broken code
mvn clean test -T $(($(nproc) * 2))
# Result: Compilation errors + can't run tests = confusing output
# ✅ CORRECT: Fix compilation first
mvn clean compile -T $(($(nproc) * 2)) -DskipTests
# Result: Clear compilation errors, fix them one by one
# Then once compilation works:
mvn test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
Solution: Check for:
Debug: Run sequentially first
mvn clean compile test
Then try parallel:
mvn clean compile -T $(($(nproc) * 2)) test -Dparallel=classes -DthreadCount=$(($(nproc) * 4))
Solution:
mvn clean
mvn generate-sources -T $(($(nproc) * 2))
target/generated-sources/antlr4/Solution: Use XML filtering
# Find failures
grep -l "failures=\"[1-9]" target/surefire-reports/*.xml
# Extract failure details
for f in $(grep -l "failures=\"[1-9]" target/surefire-reports/*.xml); do
echo "=== $f ==="
grep -A 10 "failure message" "$f"
done
Solution: Targeted sequential run with maximum verbosity
mvn test -Dtest=MyTest#specificMethod \
-DtrimStackTrace=false \
-Dsurefire.printSummary=true \
-X 2>&1 | tee test-debug.log
Code Change Type:
├── Compilation errors / syntax issues
│ └── mvn clean compile -T $(($(nproc) * 2)) -DskipTests (focus on fixing compilation first)
│
├── ANTLR4 grammar (.g4 files)
│ └── mvn clean generate-sources -T $(($(nproc) * 2)) && mvn compile -T $(($(nproc) * 2)) -DskipTests
│ (then after compilation verified: mvn test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4)))
│
├── Major refactoring / dependency changes
│ └── mvn clean compile -T $(($(nproc) * 2)) test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
│
├── Normal code changes (Java/Scala)
│ └── mvn compile -T $(nproc) test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
│
├── Only tests changed
│ └── mvn test -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
│
└── Debugging specific test failure
├── First: mvn test -Dtest=TestClass -DtrimStackTrace=false
└── Then: mvn test -Dtest=TestClass#method -DtrimStackTrace=false -X
-DskipTests when debugging compilation errors - tests can't run if code doesn't compile-T $(nproc) or -T $(($(nproc) * 2)) unless debugging (dynamically calculated)-Dparallel=classesAndMethods for maximum throughputhtopmvn clean is cheap insurance against stale builds# Clean parallel build (skip tests for compilation debugging)
mvn clean compile -T $(($(nproc) * 2)) -DskipTests
# Clean build + parallel tests
mvn clean test -T $(($(nproc) * 2)) -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
# Re-generate sources (ANTLR4, etc.) - skip tests until compilation verified
mvn clean generate-sources -T $(($(nproc) * 2))
mvn compile -T $(($(nproc) * 2)) -DskipTests
# Run specific test verbosely
mvn test -Dtest=MyTest -DtrimStackTrace=false
# Run only failed tests from last run
mvn surefire:test
# Full clean with verify (integration tests)
mvn clean verify -T $(($(nproc) * 2)) -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
# Parallel build, skip tests (for compilation debugging)
mvn clean compile -T $(($(nproc) * 2)) -DskipTests
# Single test with debug output to file
mvn test -Dtest=MyTest#method -DtrimStackTrace=false -X > debug.log 2>&1
# Run approval tests in parallel
mvn test -Dtest=ApprovalTests -Dparallel=classesAndMethods -DthreadCount=$(($(nproc) * 4))
# Debug single approval test case
mvn test -Dtest="ApprovalTests#*testCase001*" -DtrimStackTrace=false
When using this skill:
target/classes/ (Java/Scala)target/test-classes/target/generated-sources/target/surefire-reports/ (XML + TXT)target/failsafe-reports/-T flag specifies threads: -T $(nproc) = 1 per core, -T $(($(nproc) * 2)) = 2 per core, dynamically calculated$((...)) to calculate thread counts based on available coresthreadCount for tests is independent of Maven's -T setting and also dynamically calculated$(free -g | awk '/^Mem:/{print int($2 / 2)}')g for 50% of total RAM (rounded down).xml and .txt reports for easy analysisxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience