Skip to content

Commit

Permalink
Add build scripts for faster local compilation (#14618)
Browse files Browse the repository at this point in the history
- Add MAVEN_OPTS to improve build performance
- Implement incremental build and caching
- Add options for clean, install, compile, test, and spotless goals
- Allow specifying modules and profiles
- Improve help messages and usage instructions
- Unify build script behavior across Windows and Unix-like systems
  • Loading branch information
oxsean authored Sep 3, 2024
1 parent 51f4f74 commit 067dc8d
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<extensions>
<extension>
<groupId>org.apache.maven.extensions</groupId>
<artifactId>maven-build-cache-extension</artifactId>
<version>1.2.0</version>
</extension>
</extensions>
33 changes: 33 additions & 0 deletions .mvn/maven-build-cache-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0 https://maven.apache.org/xsd/build-cache-config-1.0.0.xsd">
<configuration>
<enabled>false</enabled>
</configuration>
<input>
<global>
<includes>
<include>src/main</include>
</includes>
<excludes>
<exclude>pom.xml</exclude>
<exclude>.flattened-pom.xml</exclude>
</excludes>
</global>
</input>
</cache>
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
125 changes: 125 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/sh

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -eu

cd "$(dirname "$0")"

export MAVEN_OPTS="\
-Xms2g \
-Xmx2g \
-XX:+UseG1GC \
-XX:InitiatingHeapOccupancyPercent=45 \
-XX:+UseStringDeduplication \
-XX:-TieredCompilation \
-XX:TieredStopAtLevel=1 \
-Dmaven.build.cache.enabled=true \
-Dmaven.build.cache.lazyRestore=true \
-Dmaven.compiler.useIncrementalCompilation=false \
-Dmaven.test.skip=true \
-Dcheckstyle.skip=true \
-Dcheckstyle_unix.skip=true \
-Drat.skip=true \
-Dmaven.javadoc.skip=true
"

CMD="./mvnw -e --batch-mode --no-snapshot-updates --fail-fast -T 2C"
ARGS=""
MODULES=""
PROFILES="sources,skip-spotless"
DEFAULT_MODULES="dubbo-distribution/dubbo-all,dubbo-spring-boot/dubbo-spring-boot-starter"

print_help() {
echo "Usage: $0 [options]"
echo "Fast local compilation with incremental build and caching"
echo "Options:"
echo " -c Execute clean goal (removes build artifacts)"
echo " -i Execute install goal (builds and installs the project)"
echo " -p Execute compile goal (compiles the source code)"
echo " -t Execute test goal (runs the tests)"
echo " -s Execute spotless:apply (format the code)"
echo " -d Execute dependency:tree (displays the dependency tree)"
echo " -m Specify modules, default is $DEFAULT_MODULES"
echo " -f Specify profiles, default is $PROFILES"
echo " -h Display this help message"
echo ""
echo "Examples:"
echo " $0 -ci Execute clean, install goals"
echo " $0 -s Execute spotless:apply"
echo " $0 -t -m dubbo-config Execute test goal for dubbo-config module"
echo " $0 -cp -m dubbo-common Execute clean, compile the dubbo-common module"
echo " $0 -d Display the dependency tree"
exit 0
}

while getopts ":ciptdsm:f:h" opt; do
case $opt in
c)
ARGS="$ARGS clean"
;;
i)
ARGS="$ARGS install"
;;
p)
ARGS="$ARGS compile"
;;
t)
ARGS="$ARGS test"
export MAVEN_OPTS=$(echo "$MAVEN_OPTS" | sed 's/-Dmaven\.test\.skip=true/-Dmaven.test.skip=false/')
;;
d)
ARGS="$ARGS dependency:tree"
;;
s)
ARGS="$ARGS spotless:apply"
PROFILES="sources"
;;
m)
MODULES="-pl $OPTARG -am"
;;
f)
PROFILES="$OPTARG"
;;
h)
print_help
;;
*)
if [ "$OPTARG" = "m" ]; then
MODULES=" -pl $DEFAULT_MODULES -am"
else
echo "Error: Unknown option -$OPTARG" >&2
print_help
exit 1
fi
;;
esac
done

shift $((OPTIND -1))

if [ -z "$ARGS" ] && [ -z "$@" ]; then
ARGS="install"
fi

if [ -n "$@" ]; then
ARGS="$ARGS $@"
fi

set -x
$CMD $ARGS$MODULES -P $PROFILES
113 changes: 113 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one or more
@REM contributor license agreements. See the NOTICE file distributed with
@REM this work for additional information regarding copyright ownership.
@REM The ASF licenses this file to You under the Apache License, Version 2.0
@REM (the "License"); you may not use this file except in compliance with
@REM the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing, software
@REM distributed under the License is distributed on an "AS IS" BASIS,
@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@REM See the License for the specific language governing permissions and
@REM limitations under the License.
@REM ----------------------------------------------------------------------------

@echo off
setlocal enabledelayedexpansion

set MAVEN_OPTS=^
-Xms2g ^
-Xmx2g ^
-XX:+UseG1GC ^
-XX:InitiatingHeapOccupancyPercent=45 ^
-XX:+UseStringDeduplication ^
-XX:-TieredCompilation ^
-XX:TieredStopAtLevel=1 ^
-Dmaven.build.cache.enabled=true ^
-Dmaven.build.cache.lazyRestore=true ^
-Dmaven.compiler.useIncrementalCompilation=false ^
-Dcheckstyle.skip=true ^
-Dcheckstyle_unix.skip=true ^
-Drat.skip=true ^
-Dmaven.javadoc.skip=true

set CMD=mvnw.cmd -e --batch-mode --no-snapshot-updates --fail-fast -T 2C
set ARGS=
set MODULES=
set PROFILES=sources,skip-spotless
set DEFAULT_MODULES=dubbo-distribution/dubbo-all,dubbo-spring-boot/dubbo-spring-boot-starter
set TEST_SKIP=true

goto parse_args

:print_help
echo Usage: %0 [options]
echo Fast local compilation with incremental build and caching
echo Options:
echo -c Execute clean goal (removes build artifacts)
echo -i Execute install goal (builds and installs the project)
echo -p Execute compile goal (compiles the source code)
echo -t Execute test goal (runs the tests)
echo -s Execute spotless:apply (format the code)
echo -d Execute dependency:tree (displays the dependency tree)
echo -m Specify modules, default is %DEFAULT_MODULES%
echo -f Specify profiles, default is %PROFILES%
echo -h Display this help message
echo.
echo Examples:
echo %0 -c -i Execute clean, install goals
echo %0 -s Execute spotless:apply
echo %0 -t -m dubbo-config Execute test goal for dubbo-config module
echo %0 -c -p -m dubbo-common Execute clean, compile the dubbo-common module
echo %0 -d Display the dependency tree
exit /b

:parse_args
set ARG=%~1
if "%ARG%"=="" goto check_args
if "%ARG%"=="-c" set ARGS=%ARGS% clean
if "%ARG%"=="-i" set ARGS=%ARGS% install
if "%ARG%"=="-p" set ARGS=%ARGS% compile
if "%ARG%"=="-t" (
set ARGS=%ARGS% test
set TEST_SKIP=false
)
if "%ARG%"=="-s" (
set ARGS=%ARGS% spotless:apply
set PROFILES=sources
)
if "%ARG%"=="-d" set ARGS=%ARGS% dependency:tree
if "%ARG%"=="-m" (
if "%~2"=="" (
set MODULES= -pl %DEFAULT_MODULES% -am
) else (
set MODULES= -pl %~2 -am
shift
)
)
if "%ARG%"=="-f" (
set PROFILES=%~2
shift
)
if "%ARG%"=="-h" goto print_help
if "%ARG:~0,1%" neq "-" (
set ARGS=%ARGS% %ARG%
)
shift
goto parse_args

:check_args
if "%TEST_SKIP%"=="true" (
set MAVEN_OPTS=%MAVEN_OPTS% -Dmaven.test.skip=true
)
if "%ARGS%"=="" (
set ARGS= install
)

@echo on
%CMD%%ARGS%%MODULES% -P %PROFILES%

endlocal

0 comments on commit 067dc8d

Please sign in to comment.