Gradle不更新角度依赖

时间:2017-05-23 11:30:03

标签: angularjs grails gradle

我已将angular-cookies添加到我的gradle构建中作为NPM依赖:

clientDependencies {
    npm {
        'angular'('1.5.x', into: 'angular') {
            include 'angular.js'
        }
        'angular-mocks'('1.5.x', into: 'angular') {
            include 'angular-mocks.js'
        }
        'angular-resource'('1.5.x', into: 'angular') {
            include 'angular-resource.js'
        }
        'angular-ui-bootstrap'('1.3.x', into: 'angular') {
            include 'ui-bootstrap-tpls.js'
        }
        'angular-ui-router'('0.2.x', into: 'angular', from: 'release') {
            include 'angular-ui-router.js'
        }
        'bootstrap'('3.3.x', into: 'bootstrap', from: 'dist/css') {
            include 'bootstrap.css'
        }
        'angular-cookies'('1.5.x', into: 'angular') {
            include 'angular-cookies.js'
            include 'angular-cookies.min.js'
        }

    }
}

根据grails 3.2.6的理解,这应该在我的资产文件夹/vendor/angular/中安装和管理依赖项?

但是,它似乎没有更新,我错过了依赖性错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module fytrnlt 
due to:
Error: [$injector:modulerr] Failed to instantiate module fytrnlt.fytrnlt due to:
Error: [$injector:modulerr] Failed to instantiate module ngCookies due to:
Error: [$injector:nomod] Module 'ngCookies' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

http://errors.angularjs.org/1.5.11/ $注射器/ NOMOD?P0 = ngCookies

我也把它包含在我的js文件中。

angular
    //.module("fytrnlt.fytrnlt")
    .module("fytrnlt.fytrnlt", ["ngCookies"])
    .factory('authInterceptor', function ($rootScope, $window) {
        return {
            request: function (config) {
                config.headers = config.headers || {};
                if ($window.sessionStorage.token) {
                    config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
                }
                return config;
            }
        };
    })
    .config(function ($httpProvider) {
        $httpProvider.interceptors.push('authInterceptor');
    })
    .controller("FytrnltListController", FytrnltListController);
//function FytrnltListController(Fytrnlt){
//function FytrnltListController(Fytrnlt, $http, $window) {
function FytrnltListController(Fytrnlt, $http, $window, $rootScope, $cookies) {
    var vm = this;

    var max = 1000, offset = 0;

    /* working code without login checking
    Fytrnlt.list({max: max, offset: offset}, function(data) {
        vm.fytrnltList = data;
    });
    */

   // vm.authenticated = false;
   // $rootScope.authenticated = false;

    //try new logic to fetch cookie
    vm.loggedcookie = $cookies.get('globals'); //see code further down

    if(vm.authenticated == null){
        vm.authenticated = false;
    }

if( $rootScope.authenticated == null)
{
    $rootScope.authenticated = false;

}
    vm.login = function () {
        $http.post('/api/login', {
            username: vm.user.username,
            password: vm.user.password
        }).then(function (response) {
            vm.authenticated = true;
            $rootScope.authenticated = true;

            //store user
            $rootScope.globals = {
                currentUser: {
                    username: username
                }
            };
            //store in cookie because I am having an arch issue
            var cookieExp = new Date();
            cookieExp.setDate(cookieExp.getDate()+1);
            //$cookies.putObject('globals', $rootScope.globals,{expires: cookieExp});
            $cookies.put('globals', $rootScope.globals,{expires: cookieExp});


                $window.sessionStorage.token = response.data.access_token;
                Fytrnlt.list({max: max, offset: offset}, function(data) {
                    vm.fytrnltList = data;
                });
        });
    };
}

我也把它包含在fytrnlt.fytrnlt.js中

/= wrapped
//= require /angular/angular 
//= require /angular/angular-ui-router
//= require /angular/angular-cookies
//= require /angular/angular-resource
//= require /fytrnlt/core/fytrnlt.core
//= require /fytrnlt/fybkbra/fytrnlt.fybkbra
//= require /fytrnlt/spriden/fytrnlt.spriden
//= require_self
//= require_tree services
//= require_tree controllers
//= require_tree directives
//= require_tree domain
//= require_tree templates

angular.module("fytrnlt.fytrnlt", [
    "ui.router",
    "ngResource",
    "ngCookies", //added May23/17
    "fytrnlt.core",
    "fytrnlt.fybkbra",
    "fytrnlt.spriden"
]).config(config);

function config($stateProvider) {
    $stateProvider
        .state('fytrnlt', {
            url: "/api/fytrnlt",
            abstract: true,
            template: "<div ui-view></div>"
        })
        .state('fytrnlt.list', {
            url: "",
            templateUrl: "/fytrnlt/fytrnlt/list.html",
            controller: "FytrnltListController as vm"
        })
        .state('fytrnlt.create', {
            url: "/create",
            params: {"fybkbraId":null,"spridenId":null, "fyrsignId":null},
            templateUrl: "/fytrnlt/fytrnlt/create.html",
            controller: "FytrnltCreateController as vm"
        })
        .state('fytrnlt.edit', {
            url: "/edit/:id",
            templateUrl: "/fytrnlt/fytrnlt/edit.html",
            controller: "FytrnltEditController as vm"
        })
        .state('fytrnlt.show', {
            url: "/show/:id",
            templateUrl: "/fytrnlt/fytrnlt/show.html",
            controller: "FytrnltShowController as vm"
        })
        .state('fytrnlt.firemyvalidations', {
        url: "/firemyvalidations",
        templateUrl: "/fytrnlt/fytrnlt/fvalid.html",
        //controller: "FytrnltShowController as vm"
            //controller: "Fytrnlt as vm"
            //TestReturnmyList
    });
}

文件夹..\Vendor\angular\缺少angular-cookies.js

Project Structure

1 个答案:

答案 0 :(得分:0)

您似乎正在使用&#34; com.craigburke.client-dependencies&#34;插入。我尝试了两个&#34; com.craigburke.client-dependencies&#34;和&#34; com.moowork.node&#34; gradle插件,找到&#34; com.moowork.node&#34;与客户端依赖相比,它易于使用,而且非常干净。

在build.gradle中:



    buildscript {
        repositories {
            mavenCentral()
            mavenLocal()
            jcenter()
        }
        dependencies {
        }
    }
    plugins {
      id "com.moowork.node" version "1.2.0"
    }
    ....
    node {
      version = '6.11.3'
      npmVersion = '3.10.10'
      download = true
      nodeModulesDir = file("./node_modules")
      workDir = file("./node_modules/nodejs")
    }

然后运行:gradle npmInstall,它将安装依赖项。