本文介绍了如何引用作为gradle依赖下载的bootstrap的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我不确定如何引用项目中外部库中的引导库。

My question is that i am not sure how to refer to the bootstrap lib which is in the 'External Libraries' in my project.

在build.gradle文件中,我添加了:

编译组:'org.webjars',名称:'bootstrap ',版本:'3.3.7'

In the build.gradle file i added:
compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'

因此下载了引导程序库。
但是当我想在html文件中引用它并尝试使用复制路径函数时,我得到这个:

so the bootstrap library was downloaded. But when i want to refer to it in a html file, and try to use the copy path function, i get this:

C:\Users\Michael\.gradle\caches\modules-2\files-2.1\org.webjars\bootstrap\3.3.7\d6aeba80236573ed585baa657dac2b951caa8e7e\bootstrap-3.3.7.jar!\META-INF\resources\webjars\bootstrap\3.3.7\css\bootstrap.css

还尝试了这个'标准'路径(不工作):

Also tried this 'standart' path (wasnt working):

<link rel="stylesheet" href="../css/bootstrap.min.css">    

我正在使用Intellij(gradle项目)

I am using Intellij ( gradle project )

下找到

推荐答案

Gradle下载和本地。它会在需要时引用缓存中的工件,IDE,编译器都从缓存中获取工件的路径。
您最终引用的引用引用缓存中存档中的文件。这不是浏览器理解的东西。

Gradle downloads and cahces dependecies locally. It references the artifacts from the cache whenever needed, the IDE, the compiler all get a path to the artifact from the cache. The reference that you ended up including refers the file from within the archive in the cache. This is not something the browser understands.

您需要使用将其放置在您可以访问它的项目中的某个位置,或者将其与您网站的其余部分一起打包。
复制特定的依赖关系是。
您需要另外提取工件。该文档包含有关如何的示例。

You need to use a Copy Task to place it somewhere in your project where you will be able to access it, or package it together with the rest of your website.Copying a specific dependency is already addressed. You will need to additionally extract the artifact. The documentation has examples on how to read archive contents.

以下是完整解决方案的样子:

Here's what a complete solution might look like:

apply plugin: "java"

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'
}

task copyBootstrap(type: Copy) {
   configurations.compile
     .files({ it.group.equals("org.webjars")})
     .each {
      from zipTree(it)
     }
   into "$buildDir/static_resources"
}

这会将您要查找的文件放在我的系统上的以下位置(Gradle 2.14.1):

This puts the file you are looking for at the following location on my system (Gradle 2.14.1):

build/static_resources/META-INF/resources/webjars/bootstrap/3.3.7/css/bootstrap.min.css

如果你是nt仅提取特定文件或删除版本号,以便更容易引用

In case you want to extract the specific file only or get rid of the version number to make it easier to refer to that's also possible.

请注意,这是一个好主意在 $ buildDir 中提取,因为对于大多数插件,包括java,它都是由Clean任务自动清理的,并且更难以意外提交。

Note that it's a good idea to extract in $buildDir since with most plugins, including java, it's cleaned up automatically by the Clean task, and it's harder to accidentally commit.

这篇关于如何引用作为gradle依赖下载的bootstrap的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 19:06