Gradle --dry-run在Maven中有等价命令吗?如何查看构建任务?
Hey there! Let's tackle your two questions about Maven and Gradle's dry-run functionality clearly:
--dry-run? Gradle’s --dry-run (or shorthand -m) is super handy—it simulates your build, lists all tasks that would run, and doesn’t execute any actual work. Unfortunately, Maven doesn’t have a direct global equivalent to this exact feature, but there are a few workarounds to get similar results:
Plugin-specific dry-run parameters: Many core Maven plugins support a
dryRunflag for individual stages. For example, to test the install process without actually adding artifacts to your local repo:mvn install -Dmaven.install.dryRun=trueThis will print out all the steps that would happen during installation, but won’t make any real changes.
Skip execution with combined flags: If you want to simulate a full build (like
mvn install), you can skip the actual execution steps (compilation, testing, packaging) to avoid doing real work:mvn clean install -Dmaven.compile.skip=true -Dmaven.test.skip=true -Dmaven.packaging.skip=trueHeads up: This doesn’t list out all tasks like Gradle’s dry-run does—it just skips the heavy lifting part of the build.
./gradlew build --dry-run to see all tasks that would run when executing ./gradlew build? If we’re talking about Gradle itself, then ./gradlew build --dry-run (or ./gradlew build -m for short) is exactly the official way to do this. It’ll print every task in the build task’s dependency chain that would execute, without running any of them.
If you’re asking about Maven’s equivalent to view tasks for a build-like goal (since Maven uses package or install instead of a direct build goal), here are two methods:
Use
mvn help:describeto inspect the flow: Thehelp:describegoal lets you dig into the details of a build phase or goal, including the tasks it depends on. For example, to see what happens during thepackagephase:mvn help:describe -Dcmd=package -DdetailThe output will list all plugin goals bound to that phase, plus their execution order.
Enable debug logging with
-X: Run your Maven command with the-Xflag (for debug mode) alongside skip flags to avoid actual execution. The logs will include every task and step Maven plans to run:mvn clean package -X -Dmaven.compile.skip=trueYou’ll get a lot of extra noise, but you can parse out the sequence of tasks that would execute in a real build.
内容的提问来源于stack exchange,提问作者LIvanov




