Build local eclipse plugins using tycho pointing to local p2 repository
Asked Answered
C

3

6

I am creating some Eclipse plugin and features that require third-party plugins and features. In order to include these dependencies into my project, I created a p2 layout repository.

Note: My p2 artifacts are not Maven project... However, I am using Maven style building. Here is the pom.xml for the p2 repository

<properties>
    <tycho-version>0.18.0</tycho-version>
  </properties>

  <repositories>
        <repository>
                <id>eclipse-platform-m6</id>
                <layout>p2</layout>
                <url>http://download.eclipse.org/eclipse/updates/3.8</url>
        </repository>
  </repositories>

  <build>
    <plugins>
        <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>/mypath/target/repository</artifactRepositoryLocation>
                        <metadataRepositoryLocation>/mypath/target/repository</metadataRepositoryLocation>
                        <sourceLocation>/mypath/src</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>false</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><!-- enable the Tycho build extension -->
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho-version}</version>
            <extensions>true</extensions>
        </plugin>   
    </plugins>
  </build>

The above builds successfully, and creates (and verifies) a p2 repository. I get following structure in my target/ directory of the project

- Project
    ..
    ..
    - target
      - p2agent
         - org.eclipse.equinox.p2.core
         - org.eclipse.equinox.p2.engine
      - repository
        - features
        - plugins
          artifacts.xml 
          content.xml
      <projectname>-<version>.zip <!-- This contains same things as repository directory here -->

Now, I use Tycho for building my plugins and features and refer the p2 repository I created above. I have following project structure for my plugins and features

- bundle.parent
  - bundle.mainplugin
  - bundle.mainplugin.test.fragment 
  - bundle.mainplugin.feature

Here is my bundle.parent pom.xml

<repositories>
        <repository>
                <id>eclipse-platform-m6</id>
                <layout>p2</layout>
                <url>http://download.eclipse.org/eclipse/updates/3.8</url>
        </repository>
        <repository>
                <id>third-party-eclipse-plugins</id>
                <layout>p2</layout>
                <url>file:///.../target/repository</url>
         </repository>
  </repositories>
  <modules>
    <module>../bundle.mainplugin</module>
    <module>../bundle.mainplugin.test.fragment</module>
    <module>../bundle.mainplugin.feature</module>
  </modules>
  <build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-maven-plugin</artifactId>
      <version>${tycho-version}</version>
      <extensions>true</extensions>
    </plugin>
  </plugins>
</build>

Finally, I run goals mvn clean install on the parent pom.xml. Unfortunately, mvn-compile throws compilation issues when classes in my plugin extend some of the classes in plugins. (The classes are also required at run-time). Here is the error:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.18.0:compile (default-compile
) on project <Project Name>: 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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: copied.org.apache.maven.plugin.CompilationFailureException: Compilation failure
    at copied.org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:442)
    at org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo.execute(AbstractOsgiCompilerMojo.java:239)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more

My Question:

From the compiler errors, I believe Tycho is somehow not making these third-party artifacts available to my classes for which there is a compiler error. Is there a way to determine if my plugin classes exist in the Tycho classpath?

UPDATE

Checked availability of third-party bundles that I want to be available in Tycho reactor from this location

java -jar /home/.../eclipse-3.8.2/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -debug -consolelog -application org.eclipse.equinox.p2.director -repository file:///home/../target/repository -list

All third-party bundles showed up successfully.

Con answered 1/8, 2013 at 17:1 Comment(2)
The file:///.../target/repository URL won't work. A solution could be Laurents answer or this other question. I don't know how you even get to the compile step. I'd assume that the dependency resolution already fails.Prat
I am off that project and do not have access to the code anymore to test the solutionCon
G
3

Sebastian Zarnekow's answer gave me a hint.

Error while building an xtext project with ant: Generation of the Grammar classes fails

As you can infer from the error message, maven fails to create language models from injection. The reason is explained in the link above:

Xtext uses the platform:/resource URI scheme of EMF.

The solution is you need to give EMFGenerator a new declaration of where the model directory should be. In **.mwe2 file, replace the following code

fragment = ecore.EMFGeneratorFragment auto-inject {}

with

fragment = ecore.EMFGeneratorFragment auto-inject {
    javaModelDirectory = "/${projectName}/src-gen"
}

should do the trick.

Goober answered 22/1, 2015 at 6:18 Comment(1)
This just saved my night!! Tycho/Maven/Xtext building is way confusing, thanks for the trick.Pamella
C
1

for anyone who also runs into this problem, you can also try using:

${project.basedir}

So, say you have the following directories:

- projects:
    - main-project
    - local-repository

In the parent pom (i.e.: main-project/pom.xml) reference the local-repository, using a relative path, in the following way:

<url>file:${project.basedir}/target/repository</url>
Crackle answered 7/3, 2014 at 12:3 Comment(2)
file:${project.basedir} yields an invalid URL on Windows systems. Use ${project.baseUri} instead.Prat
Or try <url>file:${user.home}/somewhere/target/repository</url> in Linux in case your p2 repo is not in a sub-directory of your project.Newby
S
0

Just replace :

<url>file:///.../target/repository</url>

by :

<url>file:<projectname>/deploy/target/repository</url>

(if your parent pom.xml is your root folder)

Stripteaser answered 4/9, 2013 at 10:30 Comment(1)
thanks for your comment. I have moved out of the project I was working for and cannot try your suggestion.Con

© 2022 - 2024 — McMap. All rights reserved.