Issue
Small question regarding a Makefile please. We are currently using a Makefile in order to run commands. (Many many of them). One particular command, which is a java Maven build, is failing.
Here is the snippet of the Makefile:
.PHONY: help
.DEFAULT_GOAL := help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
build:
mvn clean install -U -Pintegration -Dspringdoc.writer-with-default-pretty-printer=true javadoc:javadoc checkstyle:checkstyle spotbugs:spotbugs pmd:pmd pmd:cpd org.pitest:pitest-maven:mutationCoverage jacoco:prepare-agent jacoco:report dependency:tree sonar:sonar
To emphasise, make build
here is not doing anything:
make build
make: Nothing to be done for `build'.
On an IDE, I can see the error:
$, <conditional>, <directive>, EOL, '\t' or macro expected, got ':'
To also add information, this works:
.PHONY: help
.DEFAULT_GOAL := help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
clean: ## mvn clean
mvn clean;
Invoking make clean
will actually clean. make help is also working.
But not working for this rule:
build:
mvn clean install -U -Pintegration -Dspringdoc.writer-with-default-pretty-printer=true javadoc:javadoc checkstyle:checkstyle spotbugs:spotbugs pmd:pmd pmd:cpd org.pitest:pitest-maven:mutationCoverage jacoco:prepare-agent jacoco:report dependency:tree sonar:sonar
I do not understand what does it means. May I ask how to fix this please?
To confirm, the exact same maven command run from a terminal works perfectly fine.
Thank you for your help.
Solution
Use Make "call" function.
define buildfn
mvn clean install -U -Pintegration -Dspringdoc.writer-with-default-pretty-printer=true javadoc:javadoc checkstyle:checkstyle spotbugs:spotbugs pmd:pmd pmd:cpd org.pitest:pitest-maven:mutationCoverage jacoco:prepare-agent jacoco:report dependency:tree sonar:sonar
endef
Then run it like this:
build:
$(call buildfn)
Here is reference documentation: The call function
Answered By - luqo33
Answer Checked By - David Goodson (JavaFixing Volunteer)