Comprehensive guide to building the application with Maven.
- Java 21 LTS - Required for compilation
- Maven 3.6+ - Build tool
- (Optional) Sass - For compiling stylesheets
mvn clean installWhat it does:
- Removes all previous build artifacts (
target/directory) - Downloads dependencies (first run only)
- Compiles Java sources
- Runs all unit and integration tests
- Packages application as JAR
- Installs to local Maven repository (~/.m2/repository)
Build time:
- First run: ~3-5 minutes (downloads dependencies)
- Subsequent: ~1-2 minutes
Output: target/source-code-portal-{version}.jar
mvn clean install -DskipTestsWhen to use:
- Quick iterations during development
- Building for local testing
- After making small changes
Build time: ~30-60 seconds
mvn clean packageWhat it does:
- Same as
installbut doesn't copy JAR to local Maven repo - Slightly faster if you don't need the JAR in your local repository
mvn clean compileWhen to use:
- Just checking if code compiles
- Before running tests in IDE
mvn testRuns all tests without recompiling if no changes detected.
mvn test -Dtest=TestClassNameExample:
mvn test -Dtest=SpringBootServerTest
mvn test -Dtest=CacheStoreTestmvn test -Dtest=TestClassName#methodNameExample:
mvn test -Dtest=SpringBootServerTest#testHealthEndpoint
mvn test -Dtest=GitHubCommandTest#testRateLimitmvn test -Dtest='*Controller*'
mvn test -Dtest='*Spring*'mvn clean install -DskipTests # Compile tests but don't run
mvn clean install -Dmaven.test.skip # Don't even compile tests (faster)Source Code Portal uses Sass for stylesheets. You have two options:
mvn com.github.warmuuh:libsass-maven-plugin:watchPros:
- No external dependencies
- Works on any system with Maven
Cons:
- Slower compilation
- More verbose output
First, install Sass (one-time setup):
# macOS
brew install sass/sass/sass
# Ubuntu/Debian
npm install -g sass
# Windows
choco install sassThen watch for changes:
sass --watch src/main/sass/scss:target/classes/META-INF/views/cssPros:
- Much faster (~10x)
- Cleaner output
- Better error messages
Cons:
- Requires external installation
If you just want to compile once (no watching):
# With Maven
mvn com.github.warmuuh:libsass-maven-plugin:compile
# With Sass
sass src/main/sass/scss:target/classes/META-INF/views/cssFor automatic compilation on save in IntelliJ:
- Settings → Tools → File Watchers
- Click + → Sass
- Configure:
- File type: SCSS
- Program:
/usr/local/bin/sass(adjust path) - Arguments:
$FileName$:$FileNameWithoutExtension$.css - Output paths:
$FileNameWithoutExtension$.css
- Click OK
Now CSS will compile automatically when you save SCSS files.
mvn clean install -PdevEnables:
- Debug logging
- Hot reload (with Spring Boot DevTools)
- Detailed error pages
mvn clean install -PprodEnables:
- Optimized compilation
- Minified resources
- Production logging levels
mvn clean install -PtestUsed for:
- Integration test environments
- CI/CD pipelines
Speed up builds with multiple threads:
mvn clean install -T 4 # Use 4 threads
mvn clean install -T 1C # Use 1 thread per CPU core
mvn clean install -T 2.0C # Use 2 threads per CPU coreRecommended: -T 1C on modern multi-core systems
Build without checking for dependency updates:
mvn clean install -o
# or
mvn clean install --offlineWhen to use:
- No internet connection
- Speed up builds when dependencies are already cached
Force update of SNAPSHOT dependencies:
mvn clean install -U
# or
mvn clean install --update-snapshotsFor debugging build issues:
mvn clean install -X # Debug output
mvn clean install -e # Show error stack tracesAfter a successful build, you'll find:
target/
├── source-code-portal-{version}.jar # Executable JAR
├── classes/ # Compiled Java classes
│ └── META-INF/
│ └── views/ # Thymeleaf templates
│ └── css/ # Compiled CSS
├── test-classes/ # Compiled test classes
├── maven-archiver/ # Maven metadata
└── maven-status/ # Build status
The main artifact is a "fat JAR" containing all dependencies:
ls -lh target/source-code-portal-*.jar
# ~50-60 MBYou can run it directly:
java -jar target/source-code-portal-*.jarMaven is not installed or not on PATH:
# Check installation
which mvn
# Install Maven
# macOS: brew install maven
# Ubuntu: apt install maven
# Windows: choco install mavenClean build artifacts and rebuild:
mvn clean
rm -rf target/
mvn install -DskipTestsIncrease Maven memory:
export MAVEN_OPTS="-Xmx2g -XX:MaxMetaspaceSize=512m"
mvn clean installOr set permanently in ~/.mavenrc:
MAVEN_OPTS="-Xmx2g -XX:MaxMetaspaceSize=512m"# Clear corrupted dependencies
rm -rf ~/.m2/repository/
# Retry with verbose output
mvn clean install -U -XRun specific failing test with verbose output:
mvn test -Dtest=FailingTest -XSee test reports:
cat target/surefire-reports/FailingTest.txtCheck Sass syntax:
sass --check src/main/sass/scss/main.scssCommon issues:
- Missing semicolons: Each rule must end with
; - Invalid nesting: Check bracket matching
- Import errors: Verify file paths in
@import
Update plugin versions:
mvn versions:display-plugin-updatesOr force plugin update:
mvn clean install -U- Use parallel builds:
-T 1Cfor multi-core systems - Skip tests during development:
-DskipTests - Use offline mode:
-owhen dependencies are cached - Increase Maven memory:
MAVEN_OPTS="-Xmx2g" - Use native Sass: Much faster than Maven plugin
- Use IntelliJ build: Often faster than command-line Maven
For continuous integration:
# Standard CI build command
mvn clean verify -B
# With code coverage
mvn clean verify -B jacoco:report
# With integration tests
mvn clean verify -B -Pintegration-testsThe -B flag enables batch mode (non-interactive, cleaner logs).
- Running Guide - Learn how to run the built application
- Configuration Guide - Configure the application
- Development - Testing - Learn about the test framework
- Maven official documentation: https://maven.apache.org/guides/
- Sass documentation: https://sass-lang.com/documentation/
- LEARNINGS.md - Build-related gotchas