FWIW I wrote a command line utility named Gum a year ago that fulfills this
purpose (invoke Maven from anywhere within the project structure), as well
as invoking the build using the Maven wrapper (when it exists).

This utility is found at https://github.com/kordamp/gm

By default it will invoke build commands from the root, in case you'd like
said commands to be invoked on the "nearest" POM then pass in the -gn flag,
that is for a project structure such as

----
.
├── mvnw
├── mvnw.cmd
├── pom.xml
├── pomchecker-ant-tasks
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── assembly
│       │   │   └── assembly.xml
│       │   ├── java
│       │   │   └── ...
│       │   └── resources
│       │       └── ...
│       └── site
│           └── ...
├── pomchecker-cli
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── java
│       │   │   └── ...
│       │   └── resources
│       │       └── ...
│       └── site
│           └── ...
├── pomchecker-core
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── ...
│       └── site
│           └── ...
├── pomchecker-enforcer-rules
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── ...
│       └── site
│           └── ...
├── pomchecker-maven-plugin
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── java
│       │   │   └── ...
│       │   └── resources
│       │       └── ...
│       └── site
│           └── ...
├── pomchecker-toolprovider
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── ...
│       └── site
│           └── ...
└── src
    └── site
        └── ...
----

If you happen to be inside `pomchecker-toolprovider/src/main/java` and
build like to invoke a build for just that particular module then `gm -gn
compile` but OTOH if you want to build using the root then `gm compile`.

Cheers,
Andres

-------------------------------------------
Java Champion; Groovy Enthusiast
http://andresalmiray.com
http://www.linkedin.com/in/aalmiray
--
What goes up, must come down. Ask any system administrator.
There are 10 types of people in the world: Those who understand binary, and
those who don't.
To understand recursion, we must first understand recursion.


On Wed, Jun 9, 2021 at 1:36 AM Laird Nelson <[email protected]> wrote:

> I ran into an odd situation today and want to see if it's a known problem.
>
> I work on Helidon (https://helidon.io).  (Disclaimer: I never speak for my
> employer unless I say that's what I'm doing and I'm not doing that now.)  I
> am compiling a Maven module that is also a "real" Java module (with a
> src/main/java/module-info.java file) using the maven-compiler-plugin at
> version 3.8.1 and JDK 11.
>
> I have a convenient little alias that runs Maven with -f $(findup pom.xml)
> where findup is:
>
> #!/bin/bash
> find-up () {
>   path=$(pwd)
>   while [[ "$path" != "" && ! -e "$path/$1" ]]; do
>     path=${path%/*}
>   done
>   echo "$path/$1"
> }
> find-up "$@"
>
> So: this lets me run Maven from a subdirectory.  Nice and convenient.
>
> I found that when I run Maven in this manner from src/main/java, i.e. the
> directory housing my module-info.java file, then test-compile fails, with
> several hundred error messages complaining that none of the modules in
> module-info are in the module graph.  Regular compilation of main sources
> during this run works fine.
>
> If I run it from, say, just src/main, everything works fine.  If I run it
> from, say, src/test/java, everything works fine.  If I run it from, say,
> src/main/java/io/helidon, or basically any other subdirectory, everything
> works fine.  It is only when I run it from src/main/java that the entire
> module graph is not found at test-compile time.
>
> I have turned on debugging output via -X and started hunting for things
> like relative paths, but found none.
>
> Is there something special about the current working directory when it
> contains module-info.java, either in the maven-compiler-plugin itself (in
> TestCompilerMojo, I'd assume), or, perhaps unexpectedly, in javac itself?
>
> Thanks,
> Best,
> Laird
>

Reply via email to