How to add a dependency on the com.intellij.lexer classes in Gradle?

I am working on a JFlex lexer for a plugin, and to test it, I have a separate application subproject in gradle. The application has a compile and runtime dependency on the com.intellij.lexer classes, such as FlexAdapter. I am trying to figure out how to add those dependencies to my build.gradle. My first attempt seemed to work, but I think it got the wrong version of the classes:

dependencies {
compile "com.intellij:openapi:7.0.3"
runtime "com.intellij:openapi:7.0.3"
}

 

For my next attempt, I tried scanning dependencies on the actual gradle plugin project to try and figure out the dependency to add. Using Analyze Dependencies, and selecting the class that uses FlexAdapter, I get this: 

 

But it's unclear to me what to add to build.gradle. I tried:

 

dependencies {

implementation "com.jetbrains:httpclient-4.5.2:2018.1.5"

}

but it didn't work. Why would httpclient have anything to do with it anyway?

 

Ultimately I just want to be able to use com.intellij.lexer.FlexAdapter in a non-plugin gradle build for testing purposes. 

5 comments
Comment actions Permalink

Hi Chris,

com.intellij.lexer classes can be found in com.jetbrains.intellij.idea:intellij-core@zip package at https://www.jetbrains.com/intellij-repository/releases repository. List of available versions also can be found there.

0
Comment actions Permalink

Hi Alexander, 

 

Thanks, but that didn't quite do it. I tried adding this to build.gradle:

repositories {
    maven {
        url "https://www.jetbrains.com/intellij-repository/releases"
    }
}

dependencies {
    implementation "com.jetbrains.intellij.idea:intellij-core:2018.1.5"
}

 

And it configures OK, but when I try to build I get:

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class com.[my module], unresolved supertypes: com.intellij.lexer.FlexAdapter

 

Any idea?

Thanks,

Chris

0
Comment actions Permalink

> Any idea?

Gradle cannot use zip as a compile dependency for Java. You have to unpack it and add jars as dependencies.

0
Comment actions Permalink

OK, thanks. I'll give that a try. I'm very new to Gradle so I appreciate your patience (and quick responses!). 

Chris

0
Comment actions Permalink

I got it working, thanks so much Alexander! For the benefit of others, here's what I did.

1. Downloaded the 2018.1.6 version of intellij-core.zip from https://www.jetbrains.com/intellij-repository/releases

2. Unpacked it into src/main/resources for my subproject. The directory looks like:

src/main/resources $ tree
.
└── intellij-core-2018.1.6
├── annotations.jar
├── asm-all.jar
├── batik-all.jar
├── cli-parser-1.1.jar
├── guava-21.0.jar
├── imgscalr-lib-4.2.jar
├── intellij-core-analysis.jar
├── intellij-core.jar
├── jayatana-1.2.4.jar
├── jdom.jar
├── jna.jar
├── jna-platform.jar
├── log4j.jar
├── oro-2.0.8.jar
├── picocontainer.jar
├── snappy-in-java-0.5.1.jar
├── streamex-0.6.5.jar
├── trove4j-1.0.20160824.jar
└── xmlgraphics-commons-1.5.jar

I only actually need intellij-core.jar, but I left the others there in case I need them in the future.

 

3. Added the following to my build.gradle:


repositories {
flatDir {
dirs 'src/main/resources/intellij-core-2018.1.6'
}
}

dependencies {
implementation group: "com.jetbrains.intellij.idea", name: "intellij-core", version:"2018.1.6"
}

Side note: Strangely, the 'version:"2018.1.6"' is not actually validated - I can put whatever numbers I want in there and Gradle accepts it. I guess Gradle is not unpacking the manifest from the jar to verify the version. 

 

Hopefully this will help someone.

Chris

1

Please sign in to leave a comment.