Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using maven-exec-plugin alongside with SourceCodeComponentFinderStrategy fails #59

Closed
Zaijo opened this issue Oct 30, 2017 · 4 comments
Closed

Comments

@Zaijo
Copy link
Contributor

Zaijo commented Oct 30, 2017

I have a maven multi-module application (see also #58),

Parts of the system:

  • spring boot application maven module "App module"
  • documentation maven module "documentation"
    • has main class with SpringComponentFinderStrategy and SourceCodeComponentFinderStrategy
    • has maven dependency on the App module (plus structurizr
    • Situations indocumentation module:
      • (A) without any plugins
      • (B) with maven-exec-plugin running main class of "documentation" module as a part of build process.

In situation (A) calling the documentation main manually works well and finds controller from the App module.

In situation (B) let maven build invoke the main, the following error shows up:

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/sun/tools/javadoc/Main
        at com.structurizr.analysis.SourceCodeComponentFinderStrategy.runJavaDoc(SourceCodeComponentFinderStrategy.java:118)
        at com.structurizr.analysis.SourceCodeComponentFinderStrategy.afterFindComponents(SourceCodeComponentFinderStrategy.java:62)
        at com.structurizr.analysis.ComponentFinder.findComponents(ComponentFinder.java:76)

Skipping the SourceCodeComponentFinderStrategy results in "fixing" this errors, but doesn't return any found components.

@simonbrowndotje
Copy link
Contributor

If you're using the SourceCodeComponentFinderStrategy, you'll need JAVA_HOME/lib/tools.jar on your classpath. See https://github.com/structurizr/java/blob/master/docs/supplementing-from-source-code.md for more information.

@Zaijo
Copy link
Contributor Author

Zaijo commented Oct 30, 2017

Bad luck on macOS:

Even adding this dependency:

    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <scope>system</scope>
      <version>LATEST</version>
      <systemPath>${java.home}/../lib/tools.jar</systemPath>
    </dependency>

didn't help.

@simonbrowndotje
Copy link
Contributor

Does that dependency block set the classpath for the Maven module, or the Java process that is created by the maven-exec-plugin? (sorry, I don't use Maven that often)

@Zaijo
Copy link
Contributor Author

Zaijo commented Oct 30, 2017

Ok, your hint was right. For future reference, the solution for me was:

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          ...
        </executions>
        <configuration>
          <mainClass>your.package.Documentation</mainClass>
          <includePluginDependencies>true</includePluginDependencies>  // HERE IS THE TRICK
          <includeProjectDependencies>true</includeProjectDependencies>
        </configuration>
        <dependencies>
          <dependency>   // AND HERE IS THE TRICK
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <scope>system</scope>
            <version>1.8.0</version>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
          </dependency>
        </dependencies>
      </plugin>

It's not successfully finding the spring components yet, but tweaking dependencies in this manner will surely help. Thanks.

@Zaijo Zaijo closed this as completed Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants