2

Estou adaptando o exercicio do livro "Java 9 - Interativo, reativo e modularizado - autor Rodrigo Turini" para um projeto maven modular com java 10 modular. Porem esta dando erro ao compilar o segundo modulo (http)

msartor@msartor-Latitude-E6440 ~/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore $ mvn install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] bookstore                                                          [pom]
[INFO] domain                                                             [jar]
[INFO] http                                                               [jar]
[INFO] nf                                                                 [jar]
[INFO] app                                                                [jar]
[INFO] 
[INFO] -------------------< br.com.casadocodigo:bookstore >--------------------
[INFO] Building bookstore 1.0.0                                           [1/5]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ bookstore ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ bookstore ---
[INFO] Installing /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/pom.xml to /home/msartor/.m2/repository/br/com/casadocodigo/bookstore/1.0.0/bookstore-1.0.0.pom
[INFO] 
[INFO] ---------------------< br.com.casadocodigo:domain >---------------------
[INFO] Building domain 1.0.0                                              [2/5]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ domain ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ domain ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 3 source files to /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/domain/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ domain ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ domain ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ domain ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ domain ---
[INFO] Building jar: /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/domain/target/domain-1.0.0.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ domain ---
[INFO] Attaching archive: /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/domain/target/domain-1.0.0-exec.jar, with classifier: exec
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ domain ---
[INFO] Installing /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/domain/target/domain-1.0.0.jar to /home/msartor/.m2/repository/br/com/casadocodigo/domain/1.0.0/domain-1.0.0.jar
[INFO] Installing /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/domain/pom.xml to /home/msartor/.m2/repository/br/com/casadocodigo/domain/1.0.0/domain-1.0.0.pom
[INFO] Installing /home/msartor/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore/domain/target/domain-1.0.0-exec.jar to /home/msartor/.m2/repository/br/com/casadocodigo/domain/1.0.0/domain-1.0.0-exec.jar
[INFO] 
[INFO] ----------------------< br.com.casadocodigo:http >----------------------
[INFO] Building http 1.0.0                                                [3/5]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ http ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ http ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] bookstore 1.0.0 .................................... SUCCESS [  1.013 s]
[INFO] domain ............................................. SUCCESS [  1.226 s]
[INFO] http ............................................... FAILURE [  0.046 s]
[INFO] nf ................................................. SKIPPED
[INFO] app 1.0.0 .......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.426 s
[INFO] Finished at: 2018-05-20T16:27:36-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project http: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed.: IllegalArgumentException -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :http

pom do projeto pai

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>br.com.casadocodigo</groupId>
  <artifactId>bookstore</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>



  <modules>

    <module>domain</module>
    <module>http</module>
    <module>nf</module>
    <module>app</module>

  </modules>

  <properties>
    <java.version>10</java.version>
    <start-class>br.com.casadocodigo.MainModulo</start-class>
    <maven-compiler-pluging.version>3.7.0</maven-compiler-pluging.version>
    <spring-boot.version>2.0.2.RELEASE</spring-boot.version>
  </properties>


  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-pluging.version}</version>
                <configuration>
                    <source>10</source>
                    <target>10</target>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

pom do projeto domain

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>br.com.casadocodigo</groupId>
    <version>1.0.0</version>
    <artifactId>bookstore</artifactId>
  </parent>

  <artifactId>domain</artifactId>
  <packaging>jar</packaging>

</project>

pom do projeto http

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>br.com.casadocodigo</groupId>
    <version>1.0.0</version>
    <artifactId>bookstore</artifactId>
  </parent>

  <artifactId>http</artifactId>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
        <groupId>br.com.casadocodigo</groupId>
        <artifactId>domain</artifactId>
        <version>1.0.0</version>
    </dependency>

  </dependencies>   

</project>

pom do projeto nf

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>br.com.casadocodigo</groupId>
    <version>1.0.0</version>
    <artifactId>bookstore</artifactId>
  </parent>

  <artifactId>nf</artifactId>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
        <groupId>br.com.casadocodigo</groupId>
        <artifactId>domain</artifactId>
        <version>1.0.0</version>
    </dependency>
  </dependencies>

</project>

pom do projeto app

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>br.com.casadocodigo</groupId>
    <version>1.0.0</version>
    <artifactId>bookstore</artifactId>
  </parent>

  <artifactId>app</artifactId>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
        <groupId>br.com.casadocodigo</groupId>
        <artifactId>domain</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>br.com.casadocodigo</groupId>
        <artifactId>http</artifactId>
        <version>1.0.0</version>
    </dependency>

    <dependency>
        <groupId>br.com.casadocodigo</groupId>
        <artifactId>nf</artifactId>
        <version>1.0.0</version>
    </dependency>

  </dependencies>

</project>

cada projeto tem seu module-info.java Segue abaixo.

module-info domain

module domain {
    exports br.com.casadocodigo.domain;
}

module-info http

module http {
    exports br.com.casadocodigo.http;

    requires domain;
    requires jdk.incubator.httpclient;
}

module-info nf

module nf {
    exports br.com.casadocodigo.service;
    exports br.com.casadocodigo.model;

    requires domain;
}

module-info app

module app {
    exports br.com.casadocodigo;

    requires domain;
    requires http;
    requires nf;
}

continua

Para quem quiser ver o codigo na integra, o mesmo esta no meu github https://github.com/marcelosartor/Estudo-Java10_Modular-Com-Maven_Modular

1 Resposta 1

2
+50

O plugin maven-compiler-plugin usa a biblioteca ASM, mas só as versões mais atuais conseguem interpretar bytecode da versão 10.

O POM central deve ser alterado com a seguinte configuração:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-pluging.version}</version>
                <configuration>
                    <source>10</source>
                    <target>10</target>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>6.1.1</version> 
                    </dependency>
                </dependencies>
            </plugin>
3
  • Essa dependencia resolvel meu problema de compilação. Veja se ainda podes me ajudar. Ao executar estou com o seguinte erro. Exception in thread "main" java.lang.NoClassDefFoundError: br/com/casadocodigo/http/Books at br.com.casadocodigo.MainMavenModulo.main(MainMavenModulo.java:16) Caused by: java.lang.ClassNotFoundException: br.com.casadocodigo.http.Books at
    – Marcelo
    Commented 2/06/2018 às 14:00
  • Faça outra pergunta com esse novo problema, que eu posso dar uma olhada. ;) Commented 2/06/2018 às 16:59
  • pt.stackoverflow.com/questions/303939/…
    – Marcelo
    Commented 2/06/2018 às 20:48

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .