Maven command to list lifecycle phases along with bound goals? - maven-2
I'm just learning Maven, and so this might be obvious, but I can't find an easy way to list the goals associated for each maven lifecycle phase for a given project.
I saw that the Maven default life cycle phases and corresponding default goals are documented here. My understanding so far is that each pom.xml can bind additional goals to each lifecycle phase.
So, is there a mvn command to determine the goals that will be run for each lifecycle phase for a given project? If not, I guess I just have to look through the pom.xml for each new maven project to figure this out?
The buildplan-maven-plugin is an excellent tool for showing how goals are bound to phases.
Below are examples of commands you can run. The commands will automatically download and install the plugin if it hasn't already been installed.
List goals by the order they will execute
> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list
PLUGIN | PHASE | ID | GOAL
--------------------------------------------------------------------------------------------
maven-enforcer-plugin | validate | default | enforce
maven-dependency-plugin | process-sources | default | copy-dependencies
maven-resources-plugin | process-resources | default-resources | resources
maven-compiler-plugin | compile | default-compile | compile
maven-resources-plugin | process-test-resources | default-testResources | testResources
maven-compiler-plugin | test-compile | default-testCompile | testCompile
maven-surefire-plugin | test | default-test | test
maven-jar-plugin | package | default-jar | jar
maven-assembly-plugin | package | make-assembly | single
maven-install-plugin | install | default-install | install
maven-deploy-plugin | deploy | default-deploy | deploy
Group goals by phase
> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list-phase
validate -----------------------------------------------------------------
+ maven-enforcer-plugin | default | enforce
process-sources ----------------------------------------------------------
+ maven-dependency-plugin | default | copy-dependencies
process-resources --------------------------------------------------------
+ maven-resources-plugin | default-resources | resources
compile ------------------------------------------------------------------
+ maven-compiler-plugin | default-compile | compile
process-test-resources ---------------------------------------------------
+ maven-resources-plugin | default-testResources | testResources
test-compile -------------------------------------------------------------
+ maven-compiler-plugin | default-testCompile | testCompile
test ---------------------------------------------------------------------
+ maven-surefire-plugin | default-test | test
package ------------------------------------------------------------------
+ maven-jar-plugin | default-jar | jar
+ maven-assembly-plugin | make-assembly | single
install ------------------------------------------------------------------
+ maven-install-plugin | default-install | install
deploy -------------------------------------------------------------------
+ maven-deploy-plugin | default-deploy | deploy
Group goals by plugin
> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list-plugin
maven-enforcer-plugin ---------------------------------------------------
+ validate | default | enforce
maven-dependency-plugin -------------------------------------------------
+ process-sources | default | copy-dependencies
maven-resources-plugin --------------------------------------------------
+ process-resources | default-resources | resources
+ process-test-resources | default-testResources | testResources
maven-compiler-plugin ---------------------------------------------------
+ compile | default-compile | compile
+ test-compile | default-testCompile | testCompile
maven-surefire-plugin ---------------------------------------------------
+ test | default-test | test
maven-jar-plugin --------------------------------------------------------
+ package | default-jar | jar
maven-assembly-plugin ---------------------------------------------------
+ package | make-assembly | single
maven-install-plugin ----------------------------------------------------
+ install | default-install | install
maven-deploy-plugin -----------------------------------------------------
+ deploy | default-deploy | deploy
Notes
By default, the goals search for tasks that would run if the user invoked mvn deploy. Phases such as clean won't be included. To include multiple phases in the search, use the buildplan.tasks property:
> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list -Dbuildplan.tasks=clean,deploy
mvn help:describe -Dcmd=compile (or any other valid phase)
One tool that helps is mvn help:effective-pom It will print the POM with all variables and all parent POMs expanded. This helps to understand what Maven sees. From that, it's pretty simple to find all the additional goals (which usually aren't that many).
The bigger problem is the implicit goals (i.e. when a plugin hooks itself to some phases of the lifecycle automatically). There is no easy way to see these without actually running Maven. This should become better in Maven 3. Until then, run Maven with -X which will print a whole lot of debug output plus the current phase and which plugins are executed.
If not with Maven but using m2e you can do it using the code block that you can use in a Eclipse plugin:
final IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();
final IMavenProjectFacade facade = projectRegistry.getProject(project);
projectRegistry.execute(facade, new ICallable<Void>() {
public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
MavenProject mavenProject = facade.getMavenProject(monitor);
List<MojoExecution> mojoExecutions = ((MavenProjectFacade) facade).getMojoExecutions(monitor);
LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(
mavenProject, mojoExecutions, facade.getResolverConfiguration().getLifecycleMappingId(),
monitor);
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping = mappingResult
.getMojoExecutionMapping();
Map<String, List<MojoExecutionKey>> phases = new LinkedHashMap<String, List<MojoExecutionKey>>();
for (MojoExecutionKey execution : mojoExecutionMapping.keySet()) {
List<MojoExecutionKey> executions = phases.get(execution.getLifecyclePhase());
if (executions == null) {
executions = new ArrayList<MojoExecutionKey>();
phases.put(execution.getLifecyclePhase(), executions);
}
executions.add(execution);
}
Look at full source.
Already implemented in:
http://marketplace.eclipse.org/content/phases-and-goals
It makes use of m2e's ability to compute the association of goals with phases. I am also trying to solve it at maven level.
These goals are built in to Maven now so you can just do ./mvnw buildplan:list
The plugin "product" page is now here: https://www.mojohaus.org/buildplan-maven-plugin/.
I put Chad's answer into a script (so I don't have to remember the plugin name which is really long). Put it in your ~/bin/ folder so you can use it anywhere.
#!/usr/bin/env bash
# Created based on https://stackoverflow.com/a/35610377/529256
debug=false
goal='list-phase'
build_plan='clean,deploy'
working_directories=""
for (( i=1; i<=$#; i++ )) do
case ${!i} in
-h|--help)
programName=$( basename ${0} )
echo "Lists the goals of mvn project(s) by phase in a table";
echo
echo "Usage:";
echo " ${programName} -d|--debug -g|--goal goal -b|--build_plan build_plan [*directory]";
echo
echo " --goal The goal for the buildplan-maven-plugin (default: $goal)"
echo " (possible values: list, list-plugin, list-phase)"
echo
echo " --build_plan The value of the buildplan.tasks parameter (default: $build_plan)"
echo " (examples: 'clean,install', 'deploy', 'install', etc...) "
echo
echo " [*directory] The directories (with pom.xml files) to run the command in"
exit 0;
;;
-d|--debug)
debug=true;
echo "debug = ${debug}";
;;
-b|--build_plan)
((i++))
build_plan="${!i}"
;;
-g|--goal)
((i++))
goal="${!i}"
;;
*)
working_directory="${!i}";
if [ ! -e "${working_directory}" ]; then
echo "'${working_directory}' doesn't exist";
exit 1;
fi;
if [ -z "${working_directories}" ]; then
working_directories="$working_directory"
else
working_directories="$working_directories ${!i}"
fi;
;;
esac;
done;
if [ -z "${working_directories}" ]; then
working_directories="$PWD"
fi
if [ ${debug} = true ]; then
echo "working_directories=$working_directories"
echo "goal=$goal"
echo "build_plan=$build_plan"
fi
for workingDirectory in ${working_directories}; do
pushd ${workingDirectory} > /dev/null
echo "cd $workingDirectory"
echo "mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:${goal} -Dbuildplan.tasks=${build_plan}"
mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:${goal} -Dbuildplan.tasks=${build_plan}
popd > /dev/null
done;
Related
target_link_directories for imported targets
In my project I am using MAP_IMPORTED_CONFIG_FINAL for an external library for a custom configuration FINAL. Is there some working example of how to set the target_link_directories for an imported target for the custom configuration FINAL using cmake. So here are the steps : The external library is boost-1.67.0 which I am installing using the following commands for Debug and Release respectively: .\bootstrap.bat .\b2 install --prefix=C:\Dev\third-party\vs2017\boost-1.67.0\Debug toolset=msvc-14.1 address-model=64 link=static -j8 variant=debug .\b2 install --prefix=C:\Dev\third-party\vs2017\boost-1.67.0\Release toolset=msvc-14.1 address-model=64 link=static -j8 variant=release Here is the example project with following structure boost-example/ | +-- main.cpp | +-- CMakeLists.txt | | +-- CMake/ | | | +-- AddConfiguration.cmake | +-- mpIncludeBoost.cmake | +-- mpSetupMSVCRuntime.cmake | +-- SetupConfigurations.cmake The files are found in this gitlab project: https://gitlab.com/sunayanag/boost-example. For the sln file generated note that in Visual Studio in the Linker section in Additional Library Directories I get C:/Dev/third-party/boost-1_67_0/install/lib/$(Configuration) which evaluates to C:/Dev/third-party/boost-1_67_0/install/lib/Final but this directory does not exist since Final is not a valid configuration of boost, it should be C:/Dev/third-party/boost-1_67_0/install/lib/Release instead. I was thinking a way of getting around this would be to use target_link_directories but how do I use this with cmake generator expressions in this case. Thanks
cmake not moving targets to install directory
My project is structured as follows ProjDir | - CMakeLists.txt | - SubDir1 | | - CMakeLists.txt | | - src | | - inc | - SubDir2 | | - CMakeLists.txt | | - src | | - inc I have targets in each subdirectory and the subdirectories are included in the main CMakeLists.txt as follows. add_subdirectory(${CMAKE_SOURCE_DIR}/SubDir1) add_subdirectory(${CMAKE_SOURCE_DIR}/SubDir2) My targets in each subdirectory are installed with the cmake function install. These commands are in the CMakeLists.txt of respective subdirectories and are specified per-target (see this post). install(TARGETS exe1 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin CONFIGURATIONS Release) While I'm able to successfully compile, the install command doesn't move the binaries to ${CMAKE_INSTALL_PREFIX}/bin but rather finishes after generated the output: Install the project... -- Install configuration: "" How could I resolve this?
On Linux, default build configuration is empty: neither debug, nor release, etc. It can be easily found from the CMake output: -- Install configuration: "" Because your install command is "tagged" with Release configuration, it is not triggered by default (with empty configuration).
Custom react-native project directory structure
When initializing a react native project with react-native init NativeApp a new directory with a flat project structure is created. I already have a project directory and I do not want to pollute the root directory excessively. What I want to achive is a root directory that looks like this: MyProject | - package.json | - .gitignore | - .gitattributes | - README.md | - .env | - .git | - Server | | - server.js | | - <other server files> | | - OtherProjectFolder | - node_modules | - NativeApp | - android | - ios | - app.json | - index.android.js | - index.ios.js | - ... In words, I would like the react application to share package.json and node_modules etc. with the rest of my project, without keeping all the application files in the root directory. Attempting to achieve this, I just moved the package.json, gitignore, node_modules and git files from the NativeApp directory to the MyProject directory, and used the command react-native run-android --root NativeApp, but then the build fails. How do I reorganize the react native directory structure?
Titanium SDK 5.2.2.GA won't find iOS devices
I have an app that worked fine last year on the earlier versions of sdk but now Titanium SDK 5.2.2.GA won't find iOS devices. I tried cleaning everything about appcelerator and reinstall but no luck. I also tried installing node-ios-device as a global package and in the titanium sdk 5.2.2 folder. What else can I do? I get the following error: 2016-05-11T09:34:54.590Z | DEBUG | [PLUGIN-LOAD] 0ms /Users/adi/.appcelerator/install/5.2.2/package/appc.js (node:2212) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version. 2016-05-11T09:34:54.651Z | DEBUG | [PLUGIN-LOAD] 61ms /Users/adi/.appcelerator/install/5.2.2/package/node_modules/appc-cli-titanium/appc.js 2016-05-11T09:34:54.651Z | DEBUG | run plugin: /Users/adi/.appcelerator/install/5.2.2/package/node_modules/appc-cli-titanium 2016-05-11T09:34:54.652Z | DEBUG | [PLUGIN-LOAD] 0ms /Users/adi/.appcelerator/install/5.2.2/package/node_modules/arrow/appc.js 2016-05-11T09:34:54.654Z | DEBUG | run plugin: /Users/adi/.appcelerator/install/5.2.2/package/node_modules/arrow 2016-05-11T09:34:54.656Z | TRACE | plugin "arrow" failed its "when" function check, skipping... 2016-05-11T09:34:54.657Z | TRACE | loading plugin "titanium" for command "run" CLI options via function 2016-05-11T09:34:54.658Z | TRACE | loading plugin "titanium" for command "run" CLI options via array 2016-05-11T09:34:54.660Z | TRACE | executing command "run" with the following plugins: ["titanium"] 2016-05-11T09:34:54.661Z | TRACE | Attempting to load session info from config file 2016-05-11T09:34:54.662Z | TRACE | check if session is invalidated 2016-05-11T09:34:55.350Z | TRACE | session expiry 1463560847951 false 2016-05-11T09:34:55.351Z | TRACE | session already loaded in opts.session 2016-05-11T09:34:55.352Z | DEBUG | Titanium Downloads Last Checked: 1462957150130 2016-05-11T09:34:55.480Z | TRACE | No project alloy hook; skipping update to 1.0.0 2016-05-11T09:34:56.100Z | ERROR | An uncaught exception was thrown! Cannot read property 'devices' of undefined 2016-05-11T09:34:56.101Z | ERROR | Cannot read property 'devices' of undefined 2016-05-11T09:34:56.101Z | TRACE | TypeError: Cannot read property 'devices' of undefined at iOSBuilder.<anonymous> (/Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/iphone/cli/commands/_build.js:298:11) at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/ioslib/index.js:115:12 at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/async/lib/async.js:721:13 at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/async/lib/async.js:52:16 at done (/Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/async/lib/async.js:241:17) at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/async/lib/async.js:44:16 at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/async/lib/async.js:718:17 at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/async/lib/async.js:167:37 at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/ioslib/index.js:85:6 at /Users/adi/Library/Application Support/Titanium/mobilesdk/osx/5.2.2.GA/node_modules/ioslib/lib/device.js:51:12
For anybody who encounters this, the problem is the NodeJS version, I had v6.2.0 and downgraded to v4.4.4. All works now.
Thanks Adi, I had the exact same issue v6.2.0 of Node and downgraded to v4.4.x and all works for me as well.
RabbitMQ 2.7.1 doesn't start with configuration file; Reason: function_clause
I try to use rabbit on ubuntu 12.04. After installation rabbitmq-server works fine. Than I stop it and add my configuration file. root#rabbit1:~# tail /etc/rabbitmq/rabbitmq-env.conf RABBITMQ_CONFIG_FILE=/etc/rabbitmq/myrabbitmq root#rabbit1:~# tail /etc/rabbitmq/myrabbitmq.config [{rabbit, [{cluster_nodes, {['rabbit#rabbit1', 'rabbit#rabbit2'], disc}}]}]. With this files rabbitmq-server says on start: root#rabbit1:~# rabbitmq-server Activating RabbitMQ plugins ... 0 plugins activated: +---+ +---+ | | | | | | | | | | | | | +---+ +-------+ | | | RabbitMQ +---+ | | | | | | v2.7.1 +---+ | | | +-------------------+ AMQP 0-9-1 / 0-9 / 0-8 Copyright (C) 2007-2011 VMware, Inc. Licensed under the MPL. See http://www.rabbitmq.com/ node : rabbit#rabbit1 app descriptor : /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/../ebin/rabbit.app home dir : /var/lib/rabbitmq config file(s) : /etc/rabbitmq/myrabbitmq.config cookie hash : 31CaH3BCSDNL1hDIFQzH2Q== log : /var/log/rabbitmq/rabbit#rabbit1.log sasl log : /var/log/rabbitmq/rabbit#rabbit1-sasl.log database dir : /var/lib/rabbitmq/mnesia/rabbit#rabbit1 erlang version : 5.8.5 -- rabbit boot start starting file handle cache server ...done starting worker pool ...done starting database ...BOOT ERROR: FAILED Reason: function_clause Stacktrace: [{lists,usort,[{[rabbit#rabbit1,rabbit#rabbit2],disc}]}, {rabbit_mnesia,init_db,3}, {rabbit_mnesia,init,0}, {rabbit,'-run_boot_step/1-lc$^1/1-1-',1}, {rabbit,run_boot_step,1}, {rabbit,'-start/2-lc$^0/1-0-',1}, {rabbit,start,2}, {application_master,start_it_old,4}] Erlang has closed {"Kernel pid terminated",application_controller,"{application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{rabbit,failure_during_boot}}}}}"} Kernel pid terminated (application_controller) ({application_start_failure,rabbit,{bad_return,{{rabbit,start,[normal,[]]},{'EXIT',{rabbit,failure_during_boot}}}}}) Have any suggestion what's wrong with my rabbit?
Configuration file should be like this: root#rabbit1:~# cat /etc/rabbitmq/myrabbitmq.config [{rabbit, [{cluster_nodes, ['rabbit#rabbit1', 'rabbit#rabbit2'] }]}]. It seems, that disc or ram node configures in different way than in documentation to latest version of rabbit. In this configuration two disc nodes will be created. If somebody wants ram node this node should be ommitted in configuration of this node (not in other config files).