1

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
GreenTigerEye
  • 5,917
  • 9
  • 22
  • 33
  • "angular2 and redstone mapper mongo dont work together" what does that mean exactly? Perhaps a dependency override would do (https://www.dartlang.org/tools/pub/dependencies#dependency-overrides) if just `pub get` is failing. – Günter Zöchbauer Mar 06 '18 at 11:34
  • yep pub get is failing with Resolving dependencies... Incompatible version constraints on code_transformers: - build_barback 0.4.0 depends on version >=0.5.1 <0.6.0 - redstone_mapper 0.2.0-beta.1 depends on version >=0.1.6 <0.3.0 So I have to do a dependency override with "code_transformers"? But which version? – GreenTigerEye Mar 06 '18 at 11:42

2 Answers2

2

In the Angular project adding

dependency_overrides:
  code_transformers: ^0.5.1
  analyzer: 0.30.0+4

should fix it

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • It is doing endless Resolving dependencies... I updated in the post above my pubspec.yaml. I also tried to remove all dev_dependencies and transformers but the resolving dependencies stuck in an endless loop – GreenTigerEye Mar 06 '18 at 12:32
  • I updated my answer. Not 100% sure this will work. `dependency_overrides` comes at some risk. There might be other issues, but for that I'd also need to see the dependencies of `foundation` – Günter Zöchbauer Mar 06 '18 at 12:42
  • Now with analyzer it doesnt stay in an endless loop. Is it normal that it just show an error about mongo_dart which couldn't be loaded? Resolving dependencies... Package mongo_dart has no versions that match >=0.1.40 <0.2.0 derived from: - redstone_mapper_mongo 0.2.0-beta.1 depends on version >=0.1.40 <0.2.0 – GreenTigerEye Mar 06 '18 at 12:52
  • These error message should mostly be read as "there is still some conflict". A new resolving algorithm that should provide better errors is work in progress already. – Günter Zöchbauer Mar 06 '18 at 12:54
  • 1
    I also updated my fondation pubspec.yaml in the post above. – GreenTigerEye Mar 06 '18 at 12:56
  • Sorry, but I'm not able to make this work. The main issue seems to be the `redstone_mapper_mongo` which seems to be quite old – Günter Zöchbauer Mar 06 '18 at 13:05
  • Yes angular2 and redstone_mapper_mongo seem to be quite incompatible. But is there another way to just ignore the package totally in Project A? The redstone_mapper_mongo is there not needed. However it is needed in the fondation project because there are the model objects which needs the @Field() @NotEmpty() annotations and the import statement. I dont know why such great frameworks dont be kept updated.. – GreenTigerEye Mar 06 '18 at 13:24
  • There is no way to ignore a dependency the code depends on. You could move the plain classes without the annotations to package foundation_plain and use a package in foundation extend all classed from `foundation_plain` and add the `@Field()` annotations there. In Angular you then only depend on `foundation_plain`. Not sure if this works with redstone though. – Günter Zöchbauer Mar 06 '18 at 13:35
  • Or is there a way to write a kind of an Adapter? When Project A uses the project fondation it will use an empty implementation of @Field() and @NotEmpty() which is doing nothing. Its just an empty implementation of a const class Field and NotEmpty class. But when project B uses the foundation it will do a kind of dependency_overrides so that the real package of "redstone mapper mongo" is used. Could it be possible? – GreenTigerEye Mar 06 '18 at 13:54
  • Not really. There were attempts to make configurable imports, to be able import idendifiers from different libraries (could be in different packages) depending on various criteria, but it was delayed for after Dart 2.0 because too many unsolved questions. – Günter Zöchbauer Mar 06 '18 at 14:09
  • 1
    Now it works with dependency_overrides. It's kind of tricky to create a local variant of this project and perhaps not the best decision. (See my post.) But it works just fine for me! The good thing is that a second world of model objects is avoided. – GreenTigerEye Mar 07 '18 at 07:58
  • 1
    It's a smart way doing it. – Günter Zöchbauer Mar 07 '18 at 07:59
1

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" 
GreenTigerEye
  • 5,917
  • 9
  • 22
  • 33