Tim
Tim

Reputation: 306

Eclipse linking shared codes

I'm developing an app on 2 different platforms. The base code is the same except for a special package which is platform dependant.
How do I link the project while still maintaining only 1 copy of the base code.
The problems lies in that the api has dependency on the special package which doesn't allow me to just create 3 projects, e.g Api , A , B and link them as shown below.

E.g. Proj A, Proj B, Proj API

Platform A package, api -> A app
Platform B package, api -> B app

Upvotes: 0

Views: 59

Answers (2)

Dale
Dale

Reputation: 1628

So what you really have is 2 different APIs and the same base code.

Common Code Base -> Api1
Common Code Base -> Api2

One solution is to use one project and build it according to what parameter you pass into the build. This way you maintain one project and one code base yet you can still build both solutions depending on what you pass in. You can do this by passing in the version you want in the build. If you were using Maven to build your project you could use a variable to differentiate between the two platforms.

It might look something like this

<project>
  ...
  <properties>
    <platformVerion>platformA</platformVerion>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>myartifact</artifactId>
      <version>${platformVerion}</version>
    </dependency>
  </dependencies>
  ...
</project>

Maven shows you how to do this here.

https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Available_Variables

While they are referring to a numbered version in this build, you can make it whatever you want including platformA and plateformB.

Now you still have the issue of where the code is picked up of the two different APIs that are using. That can be stored locally on your system or within a local repository like Lexis. For locally stored code you could use Maven's System Dependencies in manage this.

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Or better yet if you have your own local repo for the company like Lexus, put the two versions up there and simply point to them accordingly.

Hope this helps.

Upvotes: 2

Tim
Tim

Reputation: 306

I've suddenly remember that you could link files to another project.

This is the projects I created and how I solved it.

Project Base -> Base API (you can just use a folder, note if you create a project, this would throw an error as the dependencies are missing) Project Platform A -> A packages Project Platform B -> B packages

Project A API -> link Base API files, include Platform A Project B API -> link Base API files, include Platform B

Now you are able to compile the base API after including the missing platform packages.

Upvotes: 0

Related Questions