dependencies org.apache.pdfbox.pdmodel

Hello.

I tested my java code with
import org.apache.pdfbox.pdmodel.PDDocument
and it worked very well.

Then I used:
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

public class GradleTutorial {

gradle clean works. But gradle build produces a lot of errors.
It seems to build a fat-jar. Is there another method to accomplish it?

my build.gradle

repositories {
mavenCentral()
}

apply plugin: “java”

dependencies {

compile 'org.apache.pdfbox:pdfbox:1.8.14'

}

sourceSets {
main.java.srcDir “src/main/java/”
}

jar {
from configurations.compile.collect { zipTree it}
manifest.attributes “Main-Class”: “GradleTutorial”
}

Hi everyone,
I have such a similar problem. My project is a Spring Boot with Gradle as a dependency manager. I included PdfBox dependency in my “build.gradle” file, but from my app I’m not able to use its classes since they “cannot be resolved”. I don’t know what’s wrong with my files.
Here is my build.gradle

plugins {
	id 'org.springframework.boot' version '2.3.0.RELEASE'
	id 'io.spring.dependency-management' version '1.0.9.RELEASE'
	id 'java'
}

group = 'com.demo'
sourceCompatibility = '11'

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation('org.springframework.boot:spring-boot-starter-web-services') {
		exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
	}
	implementation 'commons-io:commons-io:2.7'
	implementation 'commons-codec:commons-codec:1.14'
	compileOnly 'com.googlecode.xades4j:xades4j:1.5.1'
	compileOnly 'org.projectlombok:lombok'
	compileOnly 'org.apache.pdfbox:pdfbox:2.0.20'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation('org.springframework.boot:spring-boot-starter-test') {
		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
	}
}

test {
	useJUnitPlatform()
}

Then I try to do this in my java app

    PDDocument doc = PDDocument.load(pdfFile);

And it shows me “PDDocument cannot be resolved”. What am I doing wrong? please help.

@shiroukamui You are using compileOnly 'org.apache.pdfbox:pdfbox:2.0.20' so the classes are not available in your code. You need to use implementation instead.

Hi gotson,
Thank you so much for your help, that solved my problem. Now everything is nice and smooth. :grin: :+1: