简体   繁体   中英

grails 3 dependency service gradle

I want to ask you how to create a service with these code:

@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2')
def parser = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())

def page = parser.parse('http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR1a/eclipse-jee-luna-SR1a-linux-gtk-x86_64.tar.gz')

println page.depthFirst().find { it.text() == 'North America'}
println page.depthFirst().find { it.text().contains('North America')}   

So the idea is to create a service with similar functionallity.

I tries several approaches and non of them worked. Here is one of them: 1) replace @Grab by :

dependencies {
    compile "org.ccil.cowan.tagsoup:tagsoup:1.2

in build.gradle

2) adding in the service: import org.ccil.cowan.tagsoup or import org.ccil.cowan.tagsoup.*

3) added new repository: mavenCentral()

4) adding line in project.iml :

<orderEntry type="library" name="Gradle: org.ccil.cowan.tagsoup:tagsoup:1.2" level="project" />

What I'm missing?

Tech info: grails 3.0, Intellij 15, services create by grails create-service

I've took the dependency value from: http://mvnrepository.com/artifact/org.ccil.cowan.tagsoup/tagsoup/1.2 gradle section

Your first approach for referencing dependencies is correct in a gradle / grails project.

After that you should be able to load new org.ccil.cowan.tagsoup.Parser() just fine, if it's in one of the repositories. For example it's available in mavenCentral (which you add in 3). The import only helps to reduce clutter so that you don't need the fully-qualified class name to use the class. You probably shouldn't manage the project.iml by hand.

Could it be that only IntelliJ say there is a error but if you execute it, it just works fine?

After adding dependencies in build.gradle you need to tell IntelliJ to sync the project definition:

  1. Go to the Gradle Tool Window (View => Tool Windows => Gradle)
  2. Click on Refresh all Gradle projects (blue circular arrows)

After that the Intellij project definition (project.iml) and the Gradle project are synchronized and IntelliJ should know about the dependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM