Maven-tycho 说 Lombok 需要的工件丢失了,尽管其他依赖项工作

Maven-tycho says Lombok required artifact is missing although other dependencies work

我创建了一个 p2 存储库来添加我以后用作 tycho 依赖项的插件。然而,我偶然发现了下面关于 lombok 依赖项的错误堆栈。我知道lombok有点特殊依赖。所以我下载了它并将它添加到我的插件文件夹并安装了它。我收到的错误与插件文件夹中根本没有 lombok.jar 文件夹时不同,但错误堆栈中列出的建议并未解决问题。我还尝试了其他 Whosebug post

中讨论的解决方案

mvn package fails with Required Artifact Missing even though it exists in my Remote Repository

但我还是犯了同样的错误。我的 groovy 依赖添加没有问题。

    ``` mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO] Computing target platform for MavenProject: com.project:com.project.bbcode.parser:1.0.0-SNAPSHOT @ C:\Users\Khady\temp\bbcode-lite-parser\pom.xml
[WARNING] Missing POM for org.projectlombok:com.project.lombok:jar:1.16.8
[ERROR] Internal error: java.lang.RuntimeException: Could not resolve project dependencies: Missing:
[ERROR] ----------
[ERROR] 1) org.projectlombok:com.project.lombok:jar:1.16.8
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=org.projectlombok -DartifactId=com.project.lombok -Dversion=1.16.8 -Dpackaging=jar -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=org.projectlombok -DartifactId=com.project.lombok -Dversion=1.16.8 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) com.project:com.project.bbcode.parser:pom:1.0.0-SNAPSHOT
[ERROR] 2) org.projectlombok:com.project.lombok:jar:1.16.8
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR] com.project:com.project.bbcode.parser:pom:1.0.0-SNAPSHOT
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] project-plugins (file:C:/Users/Khady/temp/repository,  releases=false, snapshots=false),
[ERROR] eclipse-luna (http://download.eclipse.org/releases/luna, releases=false, snapshots=false),
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false),
[ERROR] projectlombok.org (http://projectlombok.org/mavenrepo, releases=true, snapshots=true)
[ERROR] -> [Help 1]
 org.apache.maven.InternalErrorException: Internal error:     java.lang.RuntimeException: Could not resolve project dependencies
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:121)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    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: java.lang.RuntimeException: Could not resolve project dependencies
    at org.eclipse.tycho.p2.resolver.P2DependencyResolver.collectPomDependencies(P2DependencyResolver.java:276)
    at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform(P2DependencyResolver.java:204)
    at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:109)
    at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:95)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:266)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    ... 11 more
Caused by:    org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
----------
1) org.projectlombok:com.project.lombok:jar:1.16.8

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.projectlombok -  DartifactId=com.project.lombok -Dversion=1.16.8 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=org.projectlombok -DartifactId=com.project.lombok -Dversion=1.16.8 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) com.project:com.project.bbcode.parser:pom:1.0.0-SNAPSHOT
        2) org.projectlombok:com.project.lombok:jar:1.16.8

----------
1 required artifact is missing.

for artifact:
  com.project:com.project.bbcode.parser:pom:1.0.0-SNAPSHOT

   from the specified remote repositories:
     project-plugins (file:C:/Users/Khady/temp/repository, releases=false,      snapshots=false),
     eclipse-luna (http://download.eclipse.org/releases/luna, releases=false, snapshots=false),
      central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false),
  projectlombok.org (http://projectlombok.org/mavenrepo, releases=true, snapshots=true)

        at    org.apache.maven.artifact.resolver.DefaultResolutionErrorHandler.throwErrors(DefaultResolutionErrorHandler.java:71)
        at  org.apache.maven.DefaultProjectDependenciesResolver.resolveImpl(DefaultProjectDependenciesResolver.java:164)
        at org.apache.maven.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:76)
        at org.apache.maven.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:60)
        at org.eclipse.tycho.p2.resolver.P2DependencyResolver.collectPomDependencies(P2DependencyResolver.java:263)
    ... 17 more
[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/InternalErrorException

```

我的POM文件(顺便有个父POM)

``` <?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>com.project</groupId>
    <artifactId>com.project.bbcode.parser</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>eclipse-plugin</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <tycho-version>0.26.0</tycho-version>
    </properties> 

    <repositories>
        <repository>
            <id>project-plugins</id>
            <url>file:C:/Users/Khady/temp/repository</url>
            <layout>p2</layout>
        </repository>
        <repository>
            <id>eclipse-luna</id>
            <layout>p2</layout>
            <url>http://download.eclipse.org/releases/luna</url>
        </repository>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
         <repository>
        <id>projectlombok.org</id>
        <url>http://projectlombok.org/mavenrepo</url>
    </repository>
    </repositories>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>test/main/groovy</testSourceDirectory>
        <resources>
          <resource>
            <directory>src/main/java</directory>
              <includes>
                <include>**/*.groovy</include>
            </includes>
          </resource>
        </resources>
        <testResources>
            <testResource>
            <directory>test/main/groovy</directory>
            <includes>
                <include>**/*.groovy</include>
            </includes>
            <excludes>
              <exclude>**/*.java</exclude>
            </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin> <!-- enable the Tycho build extension -->
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>0.26.0</version>
                <extensions>true</extensions>
            </plugin>
            <plugin> <!-- To compile java code -->
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-compiler-plugin</artifactId>
                <version>0.26.0</version>
                <configuration>
                  <compilerArgs>
                    <arg>-warn:-raw,unchecked</arg>
                  </compilerArgs>
                </configuration>
            </plugin>
            <plugin> <!-- To run tests -->
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>0.26.0</version>
                <configuration> <!-- for UI test -->
                <useUIHarness>true</useUIHarness> 
                </configuration>        
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho.extras</groupId>
                <artifactId>tycho-p2-extras-plugin</artifactId>
                <version>${tycho-version}</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>publish-features-and-bundles</goal>
                        </goals>
                        <configuration>
                            <compress>false</compress>
                            <artifactRepositoryLocation>/C:/Users/Khady/temp/repository</artifactRepositoryLocation>
                            <metadataRepositoryLocation>/mypath/target/repository</metadataRepositoryLocation>
                            <sourceLocation>/C:/Users/Khady/temp/plugins</sourceLocation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-repository-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>verify-repository</goal>
                            <goal>archive-repository</goal>
                        </goals>
                        <configuration>
                            <compress>true</compress>
                            <includeAllDependencies>true</includeAllDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>  
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-publisher-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <publishArtifacts>true</publishArtifacts>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                 <resolver>p2</resolver>
                <pomDependencies>consider</pomDependencies>
                <ignoreTychoRepositories>true</ignoreTychoRepositories>
                  <environments>
                    <environment>
                      <os>win32</os>
                      <ws>win32</ws>
                      <arch>x86</arch>
                    </environment>
                    <environment>
                      <os>linux</os>
                      <ws>gtk</ws>
                      <arch>x86_64</arch>
                    </environment>
                    <environment>
                      <os>macosx</os>
                      <ws>cocoa</ws>
                      <arch>x86_64</arch>
                    </environment>
                  </environments>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                      <compilerId>groovy-eclipse-compiler</compilerId>
                      <verbose>true</verbose>   
                      <fork>true</fork> 
                      <compilerArguments>
                        <javaAgentClass>lombok.launch.Agent</javaAgentClass>
                      </compilerArguments>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-eclipse-compiler</artifactId>
                            <version>2.9.1-01</version>
                        </dependency>
                        <!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
                        <dependency>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-eclipse-batch</artifactId>
                            <version>2.3.7-01</version>
                        </dependency>
                        <dependency>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.16.8</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <!-- DEPENDENCIES -->
    <dependencies>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-all</artifactId>
          <version>2.4.3</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.8</version>
            <scope>provided</scope>
        </dependency> 
        <dependency>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.14.1</version>
          <type>maven-plugin</type>
        </dependency>
    </dependencies>

</project>

```

Lombok 作为依赖项的行为有点不同。有两种方法可以让你的 lombok 依赖代码工作。

您可以将 lombok 添加为依赖项,如下所示,然后在每次执行 mvn clean 时使用 mvn install 使其运行。或者,如果每次执行 mvn clean 时右键单击 Eclipse 中的项目,您可以点击 Maven -> Update Project...。它应该让 lombok 重新加载。

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok-maven -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven</artifactId>
<version>1.16.8.0</version>
</dependency>

我发现所有这些都很麻烦,所以我研究了一个替代解决方案,它不需要在每次 mvn clean 后右键单击或 mvn install。我使用了 delombok 一个强大的工具来将 lombok 代码转换成你的 maven tycho 编译器可以消化的东西。 http://awhitford.github.io/lombok.maven/lombok-maven-plugin/delombok-mojo.html。只需将其添加到您的 pom 并将源文件夹的名称更改为 src/main/lombok。不要担心,当它运行时,它会 create/update src/main/java 文件夹,其中包含所有 delomboked 代码。所以 Maven 仍然会使用 src/main/java 作为源文件夹来编译所有代码。

<!--LOMBOK SCHBANG-->
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.16.8.0</version>
            <executions>
              <execution>
                <id>delombok</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>delombok</goal>
                </goals>
              </execution>
              <execution>
                <id>test-delombok</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>testDelombok</goal>
                </goals>
                <configuration>
                  <addOutputDirectory>false</addOutputDirectory>
                  <sourceDirectory>src/test/java</sourceDirectory>
                </configuration>
              </execution>
            </executions>
      </plugin>
      <!--To copy delomboked classes back into src folder-->
      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>copy-prod-resources</id>
            <phase>process-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>src/main/java</outputDirectory>
                <resources>
                    <resource>
                        <directory>target/generated-sources/delombok</directory>
                        <filtering>false</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>