Dart ignore dependency?

Issue

How can I ignore a dependency in a project?

My project setting is:

Project A: depends on Angular2 & depends on Foundation

Project Foundation: depends on Redstone_mapper_mongo

The problem is I want to use angular2 in my Project A which depends on my Project Foundation. However the Project Foundation uses the redstone mapper mongo but angular2 and redstone mapper mongo dont work together.

Question:

So in my foundation is something like this. Can I just ignore these @Field(), @NotEmpty and the import somehow in Project A? So that angular works just fine in Project A? Therefore redstone mapper mongo shouldn’t be loaded in Project A. But how can I do this?

import 'package:redstone_mapper/mapper.dart';

class Address {
  @Field()
  @NotEmpty()
  String street;

  @Field()
  @NotEmpty()
  String city;
}

[Update]

I have these dependencies in my project A now. I added
code_transformers: ^0.5.1

Project A pubspec.yaml

dependencies:
      angular: "^4.0.0+2"
      angular_forms: "^1.0.0"
      foundation:
         path: ../foundation
    dependency_overrides:
        code_transformers: ^0.5.1



    dev_dependencies:
      angular_test: ^1.0.0
      browser: ^0.10.0
      dart_to_js_script_rewriter: ^1.0.1
      test: ^0.12.30

    transformers:
    - angular:
        entry_points:
        - web/main.dart
        - test/**_test.dart
    - test/pub_serve:
        $include: test/**_test.dart
    - dart_to_js_script_rewriter

Fondation pubspec.yaml

dependencies:
  intl: "^0.15.2"
  http: "^0.11.3+16"
  great_circle_distance: "^1.0.1"
  redstone_mapper_mongo: "0.2.0-beta.1"
  jaguar_serializer: "^0.5.1"

dev_dependencies:
  browser: "^0.10.0+2"
  dart_to_js_script_rewriter: "^1.0.3"

transformers:
  - dart_to_js_script_rewriter

Solution

In the fondation project I added a local dependency of my own empty implementation

redstone_mapper_mongo:
   path: ../redstone_mapper_mongo

And in this empty implementation the Field and NotEmpty annotations are just declared.

library redstone_mapper;

class Field {
  const Field();
}

class NotEmpty {
  const NotEmpty();
}

Like this it is possible now that Project A uses the local variant and Angular2 without any issues. And without creating a second world of model objects.

I used the dependency_overrides in my project B with the real version of redstone_mapper_mongo and so the annotations @Field and @Empty are using the real implementation of the redstone_mapper_mongo. And everything works fine now.

dependency_overrides:
   redstone_mapper_mongo: "0.2.0-beta.1" 

Answered By – GreenTigerEye

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.