class JavaModuleDependency implements Serializable {

  @Nullable
  public static JavaModuleDependency copy(IdeaProject project, IdeaModuleDependency original) {
    IdeaModule targetModule = null;
    for (IdeaModule module : project.getModules()) {
      if (module.getName().equals(original.getTargetModuleName())) {
         targetModule= module;
      }
    }

    if (targetModule != null && isNotEmpty(targetModule.getName())) {
      String scope = null;
      IdeaDependencyScope originalScope = original.getScope();
      if (originalScope != null) {
        scope = originalScope.getScope();
      }
      GradleProject gradleProject = targetModule.getGradleProject();

      File projectFolder;
      try {
        projectFolder = gradleProject.getProjectIdentifier().getBuildIdentifier().getRootDir();
      }
      catch (UnsupportedMethodException ex) {
        // Old version of Gradle doesn't support getProjectIdentifier, find folder path of the root project.
        GradleProject rootGradleProject = gradleProject;
        while (rootGradleProject.getParent() != null) {
          rootGradleProject = rootGradleProject.getParent();
        }
        projectFolder = rootGradleProject.getProjectDirectory();
      }
      String moduleId = createUniqueModuleId(projectFolder, gradleProject.getPath());
      return new JavaModuleDependency(targetModule.getName(), moduleId, scope, original.getExported());
    }
    return null;
  }

  @PropertyMapping({ "myModuleName", "myModuleId", "myScope", "myExported" }) public  JavaModuleDependency(@NotNull String moduleName, @NotNull String moduleId, @Nullable String scope, boolean exported);

}