Tôi có một dự án Java trên máy tính để bàn bằng cách sử dụng Dagger2 và xây dựng với Maven. Tôi không thể chạy tuần tự compile
và package
. Đây hoạt động:Maven: biên dịch OK, gói OK, biên dịch + gói không thành công
$ mvn clean
$ mvn compile
Và công trình này, sản xuất một jar thực thi chạy mà không có lỗi:
$ mvn clean
$ mvn package
Nhưng điều này không:
$ mvn clean
$ mvn compile
$ mvn package
Khi package
được cho các mô-đun có sử dụng Dagger2 , kết quả đầu ra:
[INFO] Changes detected - recompiling the module!
Các lỗi từ mvn -e package
là:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:915)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Module này có sự phụ thuộc này:
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
Module này sử dụng trình biên dịch cắm phiên bản 3.3 như thế này:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<configuration>
<source>1.7</source>
<target>1.7</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
</plugin>
Đây chỉ là Dagger cấu hình có liên quan. Tại sao tôi không thể chạy package
sau build
?
Có thể liên quan: Tôi nghĩ rằng forceJavacCompilerUse
không còn cần thiết nữa, nhưng không có nó, Dagger dường như không chạy chút nào. Tôi gặp lỗi biểu tượng không xác định khi triển khai thành phần được tạo (DaggerMyComponent
).
Edit: Đây là toàn bộ sản lượng mvn -e package
, command prompt vào command prompt:
[email protected]:~/Projects/IDEA/Dark Matter$ mvn -e package
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent
[INFO] weapon
[INFO] scripts
[INFO] assembly
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building weapon 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ weapon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ weapon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/kevin/Projects/IDEA/Dark Matter/weapon/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................ SUCCESS [0.001s]
[INFO] weapon ............................................ FAILURE [1.641s]
[INFO] scripts ........................................... SKIPPED
[INFO] assembly .......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.735s
[INFO] Finished at: Fri Mar 11 04:32:38 MST 2016
[INFO] Final Memory: 21M/173M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:915)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
[ERROR]
[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/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :weapon
[email protected]:~/Projects/IDEA/Dark Matter$
Chỉnh sửa 2: Tôi nhận thấy rằng khi tôi chạy package
bởi bản thân sau khi clean
, nó nói nó biên dịch 6 nguồn. Đó là có bao nhiêu lớp viết tay trong dự án. Khi tôi chạy compile
trước package
, sau này cho biết nó biên dịch 8 nguồn. Có vẻ như khi dagger-compiler
chạy trên một dự án sạch sẽ, nó âm thầm tạo và biên dịch các nguồn của nó. Sau đó, package
xem các nguồn mới và cố gắng biên dịch chúng. Điều bí ẩn là tại sao nó thất bại. Chạy compile
hai lần liên tiếp không thành công theo cùng một cách.
Sửa 3: tôi đã cố gắng this answer, quy định cụ thể dagger.internal.codegen.ComponentProcessor
như là đối số -processor
. Bây giờ lần đầu tiên tôi chạy biên dịch, tôi thấy hai đèo nơi nó biên dịch 6 tập tin và sau đó 8 tập tin:
[INFO] --- maven-compiler-plugin:3.3:compile (process-annotations) @ weapon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /home/kevin/Projects/IDEA/Dark Matter/weapon/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ weapon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ weapon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/kevin/Projects/IDEA/Dark Matter/weapon/target/classes
này được mong đợi, và compile
này thành công. Nhưng sau đó nếu tôi chạy lại package
hoặc compile
, nó sẽ không giống như trước đây.
Nguồn Dagger sản xuất nằm trong /target/generated-sources/annotations
. Tôi nghĩ rằng tôi cần phải nói với Maven để làm một cái gì đó với con đường đó, nhưng tôi không biết những gì. Nó có ý nghĩa rằng compile
phát hiện các thay đổi nguồn khi nó được chạy hai lần liên tiếp, mặc dù tôi không biết tại sao dẫn đến thất bại.Có lẽ tôi cần phải chạy bước xử lý chú thích có điều kiện, nhưng tôi không biết làm thế nào để làm điều đó hoặc điều kiện nên được.
Bạn có thể hiển thị nguyên nhân lỗi xuất đầy đủ dựa trên thông báo lỗi biên dịch không phải có nhiều đầu ra hơn nữa ... – khmarbaise
@khmarbaise Đó là toàn bộ đầu ra. Điều duy nhất tôi bỏ ra là "Để biết thêm thông tin ..." boilerplate ở cuối. –
Nó không phải là. Có đầu ra gần trình biên dịch maven-plugin cho thấy vấn đề thực sự và không chỉ là phần ở cuối ... – khmarbaise