diff options
Diffstat (limited to 'build.bat')
| -rw-r--r-- | build.bat | 58 |
1 files changed, 37 insertions, 21 deletions
| @@ -2,20 +2,22 @@ | |||
| 2 | setlocal enabledelayedexpansion | 2 | setlocal enabledelayedexpansion |
| 3 | 3 | ||
| 4 | echo === 1. Cleaning Workspace === | 4 | echo === 1. Cleaning Workspace === |
| 5 | if exist bin rmdir /s /q bin | 5 | if exist bin rmdir /s /q bin |
| 6 | if exist bin-test rmdir /s /q bin-test | 6 | if exist stage rmdir /s /q stage |
| 7 | if exist fat-stage rmdir /s /q fat-stage | 7 | if exist dist rmdir /s /q dist |
| 8 | if exist app.jar del app.jar | 8 | mkdir bin\classes |
| 9 | mkdir bin | 9 | mkdir bin\test-classes |
| 10 | mkdir bin-test | 10 | mkdir stage |
| 11 | mkdir fat-stage | 11 | mkdir dist |
| 12 | 12 | ||
| 13 | echo === 2. Compiling Production Code === | 13 | echo === 2. Compiling Production Code === |
| 14 | javac -d bin -cp "lib/*" src/com/example/App.java | 14 | dir /s /b src\main\java\*.java > sources.txt |
| 15 | javac -d bin\classes -cp "lib/*" @sources.txt | ||
| 15 | if %errorlevel% neq 0 exit /b %errorlevel% | 16 | if %errorlevel% neq 0 exit /b %errorlevel% |
| 16 | 17 | ||
| 17 | echo === 3. Compiling Test Code === | 18 | echo === 3. Compiling Test Code === |
| 18 | javac -d bin-test -cp "bin;lib/*" test/com/example/AppTest.java | 19 | dir /s /b src\test\java\*.java > test-sources.txt |
| 20 | javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt | ||
| 19 | if %errorlevel% neq 0 exit /b %errorlevel% | 21 | if %errorlevel% neq 0 exit /b %errorlevel% |
| 20 | 22 | ||
| 21 | echo === 4. Running Automated Tests === | 23 | echo === 4. Running Automated Tests === |
| @@ -23,34 +25,48 @@ set "JUNIT_JAR=" | |||
| 23 | for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" | 25 | for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" |
| 24 | if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) | 26 | if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) |
| 25 | 27 | ||
| 26 | java -jar "!JUNIT_JAR!" --classpath "bin;bin-test;lib/*" --scan-class-path | 28 | rem JUnit's --class-path does NOT expand lib\* -> build it explicitly |
| 29 | set "TEST_CP=bin\classes;bin\test-classes" | ||
| 30 | for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j" | ||
| 31 | |||
| 32 | java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath | ||
| 27 | if %errorlevel% neq 0 ( | 33 | if %errorlevel% neq 0 ( |
| 28 | echo ❌ Tests failed! Aborting build package. | 34 | echo [X] Tests failed! Aborting build package. |
| 29 | exit /b %errorlevel% | 35 | exit /b %errorlevel% |
| 30 | ) | 36 | ) |
| 31 | echo ✅ Tests passed successfully! | 37 | echo [OK] Tests passed successfully! |
| 32 | 38 | ||
| 33 | echo === 5. Extracting Dependencies for Fat JAR === | 39 | echo === 5. Extracting Dependencies for Fat JAR === |
| 34 | cd fat-stage | 40 | cd stage |
| 35 | for %%j in (..\lib\*.jar) do ( | 41 | for %%j in (..\lib\*.jar) do ( |
| 36 | echo %%j | findstr /i "junit-platform-console-standalone" >nul | 42 | echo %%~nxj | findstr /i "junit-platform-console-standalone" >nul |
| 37 | if errorlevel 1 ( | 43 | if errorlevel 1 ( |
| 38 | echo Extracting: %%~nxj | 44 | echo Extracting: %%~nxj |
| 39 | jar -xf "%%j" | 45 | jar -xf "%%j" |
| 40 | ) | 46 | ) |
| 41 | ) | 47 | ) |
| 42 | if exist META-INF rmdir /s /q META-INF | 48 | |
| 49 | rem Strip signatures + manifests (they break repacking) but KEEP | ||
| 50 | rem META-INF\services so ServiceLoader-based deps still work at runtime. | ||
| 51 | if exist META-INF ( | ||
| 52 | del /s /q META-INF\*.SF >nul 2>&1 | ||
| 53 | del /s /q META-INF\*.RSA >nul 2>&1 | ||
| 54 | del /s /q META-INF\*.DSA >nul 2>&1 | ||
| 55 | del /q META-INF\MANIFEST.MF >nul 2>&1 | ||
| 56 | ) | ||
| 43 | cd .. | 57 | cd .. |
| 44 | 58 | ||
| 45 | echo === 6. Merging Assets into Fat JAR === | 59 | echo === 6. Merging Assets into Fat JAR === |
| 46 | xcopy /e /q /y bin\* fat-stage\ | 60 | rem Merge ONLY production classes on top of the extracted deps |
| 47 | jar cfm app.jar manifest.txt -C fat-stage/ . | 61 | xcopy /e /q /y /i bin\classes\* stage\ >nul |
| 62 | rem Package the whole tree (deps + your classes), not just stage\classes | ||
| 63 | jar cfe dist/app.jar com.example.App -C stage . | ||
| 48 | if %errorlevel% neq 0 exit /b %errorlevel% | 64 | if %errorlevel% neq 0 exit /b %errorlevel% |
| 49 | 65 | ||
| 50 | rmdir /s /q fat-stage | 66 | del sources.txt test-sources.txt >nul 2>&1 |
| 67 | rmdir /s /q stage | ||
| 51 | echo ====================================== | 68 | echo ====================================== |
| 52 | echo 🎉 Fat JAR Created! Run it anywhere using: | 69 | echo Fat JAR Created! Run it with: |
| 53 | echo java -jar app.jar | 70 | echo java -jar dist/app.jar |
| 54 | echo ====================================== | 71 | echo ====================================== |
| 55 | pause | 72 | pause |
| 56 | |||