Gradle 'exclude' troubleshooting: nested dependencies on both protobuf-java AND protobuf-lite - android-gradle-plugin

I am attempting to test my Android app (on device), but during the gradle build process I am getting "Error: Program type already present: com.google.protobuf.AnyProto" (or other classes).
I am using Google Firebase-Firestore DB, which implements grpc and uses nested dependency: com.google.protobuf:protobuf-lite:3.0.1.
Also, the google/Capillary library uses nested dependency: com.google.protobuf:protobuf-java:3.4.0.
If I exclude com.google.protobuf from the Capillary lib dependency only, the app will run, then crash when a needed Capillary class is instantiated, with error: "java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/protobuf/GeneratedMessageV3;"
Here are my app dependencies, without exclusions:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.google.firebase:firebase-messaging:17.5.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
//HERE ARE THE PROBLEM DEPENDENCIES:
implementation('com.google.firebase:firebase-firestore:18.2.0', {})
implementation('com.google.capillary:lib-android:1.0.0', { })
//
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
And here is the (tree) readout of gradlew app:dependencies:
...{CONTENT ABOVE OMITTED}...
+--- com.google.firebase:firebase-firestore:18.2.0
| +--- com.google.android.gms:play-services-base:16.0.1 (*)
| +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
| +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
| +--- com.google.firebase:firebase-auth-interop:16.0.1 (*)
| +--- com.google.firebase:firebase-common:16.1.0 (*)
| +--- com.google.firebase:firebase-database-collection:16.0.1
| +--- com.google.firebase:protolite-well-known-types:16.0.1
| | \--- com.google.protobuf:protobuf-lite:3.0.1
| +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
| +--- com.squareup.okhttp:okhttp:2.7.5
| | \--- com.squareup.okio:okio:1.6.0 -> 1.13.0
| +--- io.grpc:grpc-android:1.16.1
| | \--- io.grpc:grpc-core:[1.16.1] -> 1.16.1
| | +--- io.grpc:grpc-context:1.16.1
| | +--- com.google.code.gson:gson:2.7
| | +--- com.google.errorprone:error_prone_annotations:2.2.0
| | +--- com.google.code.findbugs:jsr305:3.0.2
| | +--- org.codehaus.mojo:animal-sniffer-annotations:1.17
| | +--- com.google.guava:guava:26.0-android
| | | +--- org.checkerframework:checker-compat-qual:2.5.2
| | | \--- com.google.j2objc:j2objc-annotations:1.1
| | +--- io.opencensus:opencensus-api:0.12.3
| | | \--- com.google.errorprone:error_prone_annotations:2.2.0
| | \--- io.opencensus:opencensus-contrib-grpc-metrics:0.12.3
| | +--- com.google.errorprone:error_prone_annotations:2.2.0
| | \--- io.opencensus:opencensus-api:0.12.3 (*)
| +--- io.grpc:grpc-okhttp:1.16.1
| | +--- io.grpc:grpc-core:[1.16.1] -> 1.16.1 (*)
| | +--- com.squareup.okhttp:okhttp:2.5.0 -> 2.7.5 (*)
| | \--- com.squareup.okio:okio:1.13.0
| +--- io.grpc:grpc-protobuf-lite:1.16.1
| | +--- io.grpc:grpc-core:1.16.1 (*)
| | +--- com.google.protobuf:protobuf-lite:3.0.1
| | \--- com.google.guava:guava:26.0-android (*)
| \--- io.grpc:grpc-stub:1.16.1
| \--- io.grpc:grpc-core:1.16.1 (*)
\--- com.google.capillary:lib-android:1.0.0
+--- com.google.capillary:lib:1.0.0
| \--- com.google.protobuf:protobuf-java:3.4.0
+--- com.google.crypto.tink:tink-android:1.1.0
+--- com.google.crypto.tink:apps-webpush:1.1.0
+--- com.google.protobuf:protobuf-java:3.4.0
+--- joda-time:joda-time:2.9.9
\--- com.android.support:support-annotations:27.1.1 -> 28.0.0
I have tried using several combinations of package exclusions, including fully excluding com.google.protobuf from both Firestore and Capillary and implementing either separately:
implementation('com.google.protobuf:protobuf-java:3.4.0')
//{OR}
//implementation('com.google.protobuf:protobuf-lite:3.0.1')
implementation('com.google.firebase:firebase-firestore:18.2.0', {
exclude group: 'com.google.protobuf'//, module: 'protobuf-lite'
})
implementation('com.google.capillary:lib-android:1.0.0', {
exclude group: 'com.google.protobuf'//, module: 'protobuf-java'
})
^I have tried several combinations of this, with no success.
When I exclude 'com.google.protobuf' only from the Capillary lib dependency (I am not using the grpc functionality of this library), I am able to get the app to run, however, it does crash when a necessary object from the Capillary library is instantiated, with error: "java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/protobuf/GeneratedMessageV3;"
Is anyone able to help me sort this out so that there are no redundant dependencies nor missing class definitions, without breaking the functionality of the Capillary dependency?

Related

How to make Kotlin Fuel json serializer to compile?

I'm trying to use Fuel JSON deserializer so I added it to my dependencies like this:
implementation 'com.github.kittinunf.fuel:fuel:2.2.1'
implementation 'com.github.kittinunf.fuel:fuel-json:2.2.1'
However each time I'm running ./gradlew clean build I'm getting this error:
> Task :compileKotlin FAILED
e: /DirToMyClass/MyClass.kt: (55, 26): Cannot access class 'org.json.JSONObject'. Check your module classpath for missing or conflicting dependencies
I've run ./gradlew dependencies to check that there are no other dependency importing org.json and the only one is fuel-json.
+--- com.github.kittinunf.fuel:fuel-json:2.2.1
| +--- com.github.kittinunf.fuel:fuel:2.2.1 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.60 (*)
| \--- org.json:json:20180813
What can I be missing?
I've fixed this by changing the dependencies to:
implementation 'com.github.kittinunf.fuel:fuel:2.2.1'
implementation('com.github.kittinunf.fuel:fuel-json:2.2.1') {
exclude group: 'org.json', module: 'json'
}
implementation 'org.json:json:20190722'
Using a newer version of org.json:json.

Firebase - Gradle failed on build - com.google.android.gms:play-services-measurement-base

Recently I updated all my versions in the build.gradle file and still the build fails every time.
I get this error message
The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.4,15.0.4]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
The library com.google.firebase:firebase-analytics is being requested by various other libraries at [[16.0.0,16.0.0]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
I have tried all of the solutions suggested in other posts like:
Gradle sync fails - play-services-measurement-base
Android Studio Error The library com.google.android.gms:play-services-measurement-base
com.google.android.gms:play-services-measurement-base is being requested by various other libraries
Unfortunately, nothing worked, and I am desperate.
I am using react native with Firebase and Firestore.
Got this same error and have been stuck on it all week. I had this problem with another library and ended up having to manually change the version of the conflicting library. In that case, ./gradlew :app:dependencies was able to highlight which package it was. In this case, it does not.
All I'm seeing in the analyze depenedencies call is
com.google.firebase:firebase-core:16.0.1
| +--- com.google.firebase:firebase-analytics:16.0.1 (*)
| \--- com.google.firebase:firebase-measurement-connector-impl:16.0.1
| +--- com.google.android.gms:play-services-basement:15.0.1 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
| +--- com.google.firebase:firebase-analytics:[16.0.1] -> 16.0.1 (*)
| +--- com.google.firebase:firebase-analytics-impl:[16.1.1] -> 16.1.1 (*)
| +--- com.google.firebase:firebase-common:16.0.0 (*)
| \--- com.google.firebase:firebase-measurement-connector:16.0.0
| \--- com.google.android.gms:play-services-basement:15.0.1 (*)
\--- com.google.firebase:firebase-messaging:17.0.0
+--- com.google.android.gms:play-services-basement:15.0.1 (*)
+--- com.google.android.gms:play-services-tasks:15.0.1 (*)
+--- com.google.firebase:firebase-common:16.0.0 (*)
+--- com.google.firebase:firebase-iid:[16.0.0] -> 16.0.0 (*)
\--- com.google.firebase:firebase-measurement-connector:16.0.0 (*)
which hints that its resolving at 16.0.1 which what I intended..
compile ("com.google.firebase:firebase-analytics:16.0.1") {
force = true
}
Here's my error:
* What went wrong:
Failed to notify dependency resolution listener.
> The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.0,16.0.0]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
> The library com.google.firebase:firebase-analytics is being requested by various other libraries at [[16.0.1,16.0.1]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

Exception caused by: java.lang.ClassNotFoundException: org.reactivestreams.Publisher

In a JavaFX Gradle-based application that I develop using RxJava and Kotlin in IntelliJ IDEA 2017.1.2 (Build #IC-171.4249.39), I'm getting an exception:
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: org/reactivestreams/Publisher
everytime a code like this
return Completable.complete()
is executed. Following a suggestion of a similar question Why I am getting NoClassDefFoundError: org/reactivestreams/Publisher, I've tried to add include the reactive-streams to the dependencies block of my build.gradle script
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.2'
compile 'org.reactivestreams:reactive-streams:1.0.0'
compile 'io.reactivex.rxjava2:rxkotlin:2.0.0'
}
but the problem persists. The dependency tree looks like this one:
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
compileClasspath - Compile classpath for source set 'main'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
\--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.2
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
\--- org.jetbrains:annotations:13.0
kaptTest
\--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.2
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
\--- org.jetbrains:annotations:13.0
runtime - Runtime dependencies for source set 'main' (deprecated, use 'runtimeOnly ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
testCompile - Dependencies for source set 'test' (deprecated, use 'testImplementation ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
testCompileClasspath - Compile classpath for source set 'test'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
testRuntime - Runtime dependencies for source set 'test' (deprecated, use 'testRuntimeOnly ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
| \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
+--- io.reactivex.rxjava2:rxjava:2.0.7
| \--- org.reactivestreams:reactive-streams:1.0.0
\--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)
As you can see, org.reactivestreams:reactive-streams is present in each environment.
Now, I've managed to resolve the problem by adding manually dependency on a reactive-streams-1.0.0.jar, but I don't like this solution at all.
Could somebody advice a better solution? Thanks!

Intellij downloads Gradle dependencies but cannot resolve symbols

When I try and use dependencies I have set out in my build.gradle Intellij cannot build the code and raises errors java: cannot find symbol. How can I get Intellij to recognise my dependencies?
PS: The lbrary is showing up in "External Libraries" and I am also having this issue with all my other dependencies.
In my build.gradle I have this:
...
dependencies {
...
compile 'com.squareup.okhttp:okhttp:2.1.0'
}
In my code I try and use this library:
import com.squareup.okhttp.OkHTTPClient;
...
OkHTTPClient client = new OkHTTPClient();
errors raised on both lines.
EDIT from comment: Command line build fails with the same errors, I guess I wrongly blamed Intellij. How can I tell why the dependencies are not being downloaded? They are sitting in my build.gradle in dependencies just as I showed. They are also present when running gradle dependencies under compile, default, runtime, testCompile and testRuntime, but not archives. Is that where the issue lies?
EDIT2: Ouput of gradle dependencies:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
archives - Configuration for archive artifacts.
No dependencies
compile - Classpath for compiling the main sources.
+--- com.google.code.gson:gson:2.3.1
\--- com.squareup.okhttp:okhttp:2.1.0
\--- com.squareup.okio:okio:1.0.1
default - Configuration for default artifacts.
+--- com.google.code.gson:gson:2.3.1
\--- com.squareup.okhttp:okhttp:2.1.0
\--- com.squareup.okio:okio:1.0.1
runtime - Classpath for running the compiled main classes.
+--- com.google.code.gson:gson:2.3.1
\--- com.squareup.okhttp:okhttp:2.1.0
\--- com.squareup.okio:okio:1.0.1
testCompile - Classpath for compiling the test sources.
+--- com.google.code.gson:gson:2.3.1
+--- com.squareup.okhttp:okhttp:2.1.0
| \--- com.squareup.okio:okio:1.0.1
\--- junit:junit:4.11
\--- org.hamcrest:hamcrest-core:1.3
testRuntime - Classpath for running the compiled test classes.
+--- com.google.code.gson:gson:2.3.1
+--- com.squareup.okhttp:okhttp:2.1.0
| \--- com.squareup.okio:okio:1.0.1
\--- junit:junit:4.11
\--- org.hamcrest:hamcrest-core:1.3
BUILD SUCCESSFUL
Total time: 1.82 secs

Maven command to list lifecycle phases along with bound goals?

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;