Use jar file as source set for building and static compiling 关注
We'd like to add a second content root for a module that refers to .java source files stored in a .jar file.
We can add a content root to a module through the IDE as follows:
- Click File > Project Structure
- Click Modules
- Expand and click module name (e.g., main)
- Click Sources tab
- Click Add Content Root
- Browse to and select sources.jar
- Click OK
- Click Mark as: Sources
- Click OK to accept the additional sources
This works as expected: IDEA can find the class files, compile them, and open them into the editor as read-only.
The file sources.jar resembles the following:
$ jar -tvf sources.jar
0 Thu Feb 03 08:38:56 PST 2022 META-INF/
52 Thu Feb 03 08:38:56 PST 2022 META-INF/MANIFEST.MF
0 Thu Feb 03 08:38:30 PST 2022 com/
0 Thu Feb 03 08:38:32 PST 2022 com/domain/
0 Thu Feb 03 08:38:30 PST 2022 com/domain/package/
938 Thu Feb 03 08:38:32 PST 2022 com/domain/package/SourceCode.java
How do we accomplish the same effect of adding to the content root using Gradle? For example:
plugins {
id: 'idea'
}
idea.module.contentRoot = file( "jar:${projectDir}/sources.jar!/" )
When building, this produces the following error:
Cannot convert URL 'jar:/home/user/dev/project/sources.jar!/' to a file.
For details, see StackOverflow Post.
How would you use the idea plugin to add another content root to the module without extracting the jar file contents?
请先登录再写评论。