question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jib should handle the absence of source files gracefully

See original GitHub issue

The behaviour of Jib and java plugins differs if a project does not have any source files. Cosnider the following difference.

Java plugin handles the absence of source files gracefully by skipping the compileJava task:

> Task :root-project:sub-project:compileJava NO-SOURCE
file or directory '<project_path>/src/main/java', not found
Skipping task ':root-project:sub-project:compileJava' as it has no source files and no previous output files.

Jib, on the other hand, terminates gradle execution:

warning: Could not find build output <project_path>/build/classes/java/main'
warning: No classes files were found - did you compile your project?

> Task :jibDockerBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jibDockerBuild'.
> Main class was not found, perhaps you should add a `mainClass` configuration to jib

Caused by: com.google.cloud.tools.jib.frontend.MainClassInferenceException: Main class was not found, perhaps you should add a `mainClass` configuration to jib
        at com.google.cloud.tools.jib.frontend.MainClassFinder.resolveMainClass(MainClassFinder.java:96)

It would be convenient to be able to acheive the same no-source handling behaviour in both plugins for a simpler configuration.

I would suggest to either hardcode the improvement or add a configuration option such as lenient=true/false, where in case of true the plugin would skip the task with no source files and in case of false Jib would terminate as it does now.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
chanseokohcommented, Jul 12, 2018

PS. Jib-created images have timestamps of something like CREATED: 48 years ago or 292 years ago.

This is intended. Please see #578 and #413.

0reactions
loosebazookacommented, Jul 30, 2018

Yeah, since maven is assuming we’re calling the goal on all modules, to avoid this you can use one of two options:

  1. -pl which will only execute on a specific module.
$ mvn clean compile && mvn jib:build -pl <my-module-name>
  1. Attaching goals to lifecycle phases in a profile [EDIT: this can be done without profiles]. Assuming we’re using both <modules> and the parent pom patterns. And lets assume we want the jib goal to execute in the package phase our lifecycle. pom.xml (in our jib module)
     <profiles>
      <profile>
        <id>jib</id>
        <build>
          <plugins>
            <plugin>
              <groupId>com.google.cloud.tools</groupId>
              <artifactId>jib-maven-plugin</artifactId>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>build</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profiles>

to execute this with almost the same results as mvn clean compile jib:build

$ mvn clean package -DskipTests -Pjib

We’re skipping tests, because previously compile jib:build didn’t even activate the test phase.

I must also say that the pattern of the plugin enabling/disabling itself appears in the maven ecosystem. And while it may be strange, I can’t deny that people seem to want to use it. Let me know how this works for you, and if it doesn’t we can work on another solution that fits within the standard maven model.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 10 Most Common Mistakes That Java Developers Make
Dominant in many ways, Java offers a lot for developers: strict object-oriented paradigm, architecturally agnostic virtual machine, garbage collection - all ...
Read more >
Challenge solutions - Pwning OWASP Juice Shop
Provoke an error that is neither very gracefully nor consistently handled. Any request that cannot be properly handled by the server will eventually...
Read more >
How to Fire an Employee: Tips for Letting Go
Firing someone too hastily or without taking the proper steps could lead to an uncomfortable situation or even legal issues that could damage...
Read more >
3 Common Tasks — The Yocto Project ® 4.1.999 documentation
The meta-yocto-bsp/conf/layer.conf file in the Yocto Project Source Repositories ... During the build process, BitBake displays an error on starting if it ...
Read more >
Why It's OK to Quit Your Job - TopResume
If your gut is telling you you're not where you should be in 2021, quitting your job is OK. Just consider these tips...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found